definition
x(?=y)
Match ' x ' only when ' x ' follows ' Y '. This is called positive lookup .
For example,/jack (? =sprat)/Will match to ' Jack ' only when it is followed by ' Sprat '. /jack (? =sprat| Frost)/Match ' Jack ' only when it is followed by ' sprat ' or ' Frost '. But ' sprat ' and ' Frost ' are not part of the matching results.
x(?!y)
Match ' x ' only when ' X ' is not followed by ' Y ', this is called positive negation lookup.
For example,/\d+ (?! \.) /Match a number only when the number is not followed by a decimal point. Regular expression/\d+ (?! \.) /.exec ("3.141") matches ' 141 ' but not ' 3.141 '
Form Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_Expressions
See http://www.cnblogs.com/dolphinx/p/3486214.html explain the comparison understood.
Example
<HTML><Head> </Head> <Body> <inputID= "Test"type= "text"value="" /> <inputID= "Test"type= "text"value="" /> <inputID= "Test"type= "text"value="" /> <inputID= "Test"type= "text"value="" /> <inputID= "Test"type= "text"value="" /> <Script> varTeststr= "Windows" /*1-no band expression match*/ varTestreg= /^windows. *$/ varresult=Teststr.match (Testreg); Console.log ("/^windows. *$/="+result)///^windows. *$/=windows /*2-band expression matching*/ varTestreg= /^windows (. *) $/ varresult=Teststr.match (Testreg); Console.log ("/^windows (. *) $/="+result)///^windows (. *) $/=windows 95,95 /*3-A band expression that does not record its matching results*/ varTestreg= /^windows (?:. *) $/ varresult=Teststr.match (Testreg); Console.log ("/^windows (?:. *) $/="+result)///^windows (?:. *) $/=windows /*4-forward match, match position, positive match*/ varTestreg= /^windows (? =95) 95$/ varresult=Teststr.match (Testreg); Console.log ("/^windows (? =.*) $/="+result)///^windows (=.*) $/=windows /*5-forward match, match position, negative match*/ varTeststr= "Windows Me" varTestreg= /^windows (?! me$)/ varresult=Teststr.match (Testreg); Console.log ("/^windows (?! \d*) $/="+result)///^windows (?! d*) $/=windows me </Script></Body></HTML>
Forward and backward regex expressions and their JS examples