In this paper, the positive and negative pre-investigation in regular expressions is described. Share to everyone for your reference. The specific analysis is as follows:
Let's take a look at an example and then explain what a forward check is.
Example: There is a section of "Coming soon,going GoGoGo" that asks to find COM and go. The code is as follows:
Copy Code code as follows:
<script type= "Text/javascript" >
Forward Advance Check
function T1 () {
var con = document.getelementsbyname (' content ') [0].value;
The var reg =/\b[\w]+ (? =ing\b)/g;//matches the word with ing, but not ing. Note: If ing does not add \b, similar to GOINGABC will also match.
Alert (Con.match (reg));
}
</script>
<body>
<textarea rows= "5" cols= "a" name= "content" ></textarea><br/>
<button onclick= "T1 ();" > Regular pre-check </button><br/>
</body>
In the above example to explain forward check: first detect the boundary, and then find a match with [\w]+ Word, (? =ing) that the first probe back to see if there is ing. If so, match the previous one, and if not, move the cursor backward and continue probing. This process is forward-looking: prejudge to a value.
The so-called negative forward check, is to prejudge not for a certain value. text box input is "win7,winxp,win95,win98,win2003"
Copy Code code as follows:
<script type= "Text/javascript" >
Forward Advance Check
function T1 () {
var con = document.getelementsbyname (' content ') [0].value;
var reg =/\bwin (?! 95\b)/g;//
Alert (Con.match (reg));
}
</script>
<body>
<textarea rows= "5" cols= "a" name= "content" ></textarea><br/>
<button onclick= "T1 ();" > Regular pre-check </button><br/>
</body>
The above two examples are from the forward/negative pre-check----related information Baidu Search "0 wide assertion." JS does not support forward positive/negative pre-check, and PHP support.
I hope this article will help you with your regular expression learning.