Mega Code Archive

 
Categories / JavaScript Tutorial / Regular Expressions
 

The pattern matching methods in the RegExp object require String objects

Pattern Matching Methods in the RegExp Object MethodDescription exec(str)Searches for pattern in str and returns result test(str)Searches for pattern in str and returns true if match found, otherwise false is returned (str)Same as exec(str) method <html> <SCRIPT LANGUAGE='JavaScript'> <!--     var str = "A BC 5 DEF 135 Abc.<BR>"     var span3to5 = new RegExp("[3-5]","g");     document.write(str);     document.write("Replace digits 3 to 5 with nines.<BR>");     document.write(str.replace(span3to5,"9"));     //--> </SCRIPT> </html>