The IOS Regular Expression matches the URL location in the text and obtains the URL location (to solve the problem of connecting Chinese characters)

Source: Internet
Author: User

The requirement is very simple. It is to match the hyperlink from a piece of text. The basic practice is to use a regular expression for matching. But there is such a problem.

Most regular expressions for identifying URLs on the Internet can be correctly identified if there is spaces at the end of the URL. For example.

 

I am a Chinese https://github.com/TinyQ or a Chinese

However, if the space following TinyQ is removed. The matched "" will be connected.

A lot of regular expressions were replaced to solve the problem. Paste the code here:

NSError ** regulaStr = * regex = & * response = [regex matchesInString: options: range: NSMakeRange (, [(NSTextCheckingResult * match * substringForMatch = [NSLog (@ "substringForMatch ");
}

Here we will make an update. The following regular expression is also acceptable. And it should be better.

For example, Explorerwww.chiphell.com /. It can also be identified

(Http [s] {} | ftp): // [a-zA-Z0-9 \\. \-] + \\. ([a-zA-Z] {2, 4}) (: \ d + )? (/[A-zA-Z0-9 \\.\\-~! @ # $ % ^ & * +? : _/= <>] *)?) | (Www. [a-zA-Z0-9 \. \-] + \. ([a-zA-Z] {2, 4}) (: \ d + )? (/[A-zA-Z0-9 \\.\\-~! @ # $ % ^ & * +? : _/= <>] *)?)

 

Related Article

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.