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.