Reverse pre-search in regular expression (continued)

Source: Internet
Author: User

In the previous regular expression reverse pre-Search

In JavaScript, The Regexp object is used to implement the string replacement function of the regular expression reverse pre-search,CodeIs:

// <SPAN class = 'wp _ keywordlink '> Program </span> purpose, remove the domain name in the image path <br/> var STR = ''; <br/> var reg1 =/(/ Str. match (reg1); <br/> alert (Str. replace (Regexp. $4 ,'');

This method is applicable when there is only one URL in the string, but if the string contains multiple domain names, for example:

VaR STR = ' Netease homepage <a href = "http://www.163.com"> link </a> ';

The content removed after the program is running is the second domain name is http://www.163.com. Why?

Check the regular expression carefully and you will find that"(/
"Match

// The Difference Between the greedy match is the question mark "?", Greedy ". *", not greedy ".*? "<Br/> var reg1 =/(/</p> </p>

The solution is simple, but it also shows an important problem in daily 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.