JavaEye3.0 Development Notes-rails UTF-8 support for regular expression problems

Source: Internet
Author: User
Tags expression regular expression netbeans

The Rails Actionview::helpers::texthepler module provides a number of practical methods that are useful for forum class applications, such as Auto_link, which automatically detects URLs in incoming strings. and automatically converts it to HTML hyperlink format, which is good for displaying the content of a post.

But in the development of JavaEye3.0, but found that auto_link have bugs, once the post URL followed by Chinese words, auto_link will be the URL after all the Chinese as a part of the URL format, until you hit a space, for example:

Reference

Http://www.javaeye.com website is very good

will be formatted as:

Reference

<a href= "http://www.javaeye.com site is very good" >http://www.javaeye.com site is very good </a>

It looks like you've got the source code in rails to find the answer.

Open NetBeans, hit the shortcut key Ctrl+o, in the pop-up window input: Texthelper, enter, NetBeans has helped me open the TEXT_HELPER.RB source code, through the Navigator window, very convenient to locate the Auto_link method, To take a closer look, the main fact is that this regular expression is at work:

Ruby Code

Auto_link_re =%r{
(# leading text
<\w+.*?>|        # leading HTML tag, or
[^=!: '/]| # leading punctuation, or
^ # beginning of line
)
(
(?: HT tps?:/      /)|        # protocol Spec, or
(?: www\.) # www.*
)
(
[-\w]+ # subdomain or domain
(?: \.        [-\w]+) * # remaining subdomains or domain
(?:: \d+)? # Port
(?:/ (?:(?: [~\w\+%-]| (?: [,.;:][^\s$]) +)?) * # Path
(?: \? [\w\+%&=.;   -]+)? # query string
(?: \      #[\w\-]*)? # trailing anchor
)
([[:p unct:]]|\s|<|$) # trailing text
}x unless const_d Efined? (: Auto_link_re)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.