The pattern matching methods in the RegExp object require String objects. : Introduction « Regular Expressions « JavaScript Tutorial






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>








26.1.Introduction
26.1.1.Pattern Matching
26.1.2.Defining Patterns
26.1.3.All the characters that require a backslash character to be taken literally within a pattern.
26.1.4.Pattern Attributes
26.1.5.Testing for Pattern Matches
26.1.6.The pattern matching methods in the RegExp object require String objects.