Reverse pre-search in regular Expressions (cont.) Regular Expressions

Source: Internet
Author: User

In the previous reverse lookup in regular expressions, the RegExp object is used in JavaScript to implement the string substitution function of a regular expression reverse lookup, which is:

Program purpose to remove the domain name var str in the image path = ' '; var reg1 =/(/

This usage is applicable when there is only one URL in the string, but if the string contains more than one domain name, for example:

var str = ' NetEase home <a href= "http://www.163.com" > Links </a> ';

After the program is run, the content that is removed is the second domain name http://www.163.com. This is why.

A careful look at the regular expression will show that after using "(/

The difference with greed is one more question mark "?", greed ". *", not greedy ". *?" var reg1 =/(/

The solution to the problem is simple, but it also shows an important problem in peacetime work: Inadequate program testing.

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.