js regex正則tricks

4716 ワード


  
    
< script type = " text/javascript " >
<!--
function MatchDemo(){
var r, re; //
var s = " The123 rain in Spain falls mainly in the plain " ;
re
= / ain / ig; //
r = s.match(re); //
// debugger;
// return(r); // "ain"
//

// ////////////////////////////////////
var regex = / ((T\w*)e)(\d*) / ;
var matches = regex.exec(s);
debugger ;
/*
:matches ["The123", "The", "Th", "123"]
0 "The123"
1 "The"
2 "Th"
3 "123"
index 0
input "The123 rain in Spain falls mainly in the plain"
*/
}
// -->
< / script>