if(result)
{
alert(result); // 是?test=1&ww=2&www=3,ww=2&
alert(result[0] ",0");//是?test=1&ww=2&www=3
alert(result[1] ",1");//是是ww;
{
alert("err");
}
}
}
match is actually a string method, but the parameter is indeed a regular expression. After rewriting the above example, it is as follows
function test(){
var text="index.aspx?test=1&ww=234"; //
var re = /?( w{1,}=w{1,}&){1,}w{1,}=w{1,}/;
1,}&){1,}\w{1,}=\w{1,}"
var result= text.match(re);
if(result)
alert(result);//?test=1&ww=234,test=1& . There are multiple functions that can pass regular expressions, split, search, replace, etc. but these methods are no longer suitable for verification.
Copy code
The code is as follows:
function test(){
var text=" index.aspx?test=1&ww=234"; //
var re = /?(w{1,}=w{1,}&){1,}w{1,}=w{1,} /;
// var re2 = "(\w{1,}=\w{1,}&){1,}\w{1,}=\w{1,}" var result = text.split(re); } 3 Escape characters of regular expressions
Escape characters often appear in regular expressions, such as question marks? There are special characters in regular expressions Meaning, if you need to match a question mark?, you need to escape it. Use the escape character backslash
. Both of the following are matching a string starting with the question mark
Copy Code
The code is as follows:
function test(){
var text="?test=1&ww=2&www=3";
var re = /^?(w{1,}=w{1,}&){1,}w{1,}=w{1,}/;// ?Indicates configuration question mark? // var re =new RegExp( "^\?(\w{1,}=\w{1,}&){1,}\w{1,}=\w{1,}");// \? represents a configuration question mark?
var result= re.exec(text);
if(result)
alert("err");
} }
}