Regular Expression Match Workshop : Regular Expressions « Development « JavaScript DHTML






Regular Expression Match Workshop

   
/*
JavaScript Bible, Fourth Edition
by Danny Goodman 

Publisher: John Wiley & Sons CopyRight 2001
ISBN: 0764533428
*/

<HTML>
<HEAD>
<TITLE>Regular Expression Match</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function doMatch(form) {
    var str = form.entry.value
    var delim = (form.caseSens.checked) ? "/g" : "/gi"
    var regexp = eval("/" + form.regexp.value + delim)
    var resultArray = str.match(regexp)
    if (resultArray) {
        form.result.value = resultArray.toString()
        form.count.value = resultArray.length
    } else {
        form.result.value = "<no matches>"
        form.count.value = ""
    }
}
</SCRIPT>
</HEAD>
<BODY>
<B>String Match with Regular Expressions</B>
<HR>
<FORM>
Enter a main string:<INPUT TYPE="text" NAME="entry" SIZE=60
  VALUE="Many a maN and womAN have meant to visit GerMAny."><BR>
Enter a regular expression to match:<INPUT TYPE="text" NAME="regexp" SIZE=25
  VALUE="\wa\w">
<INPUT TYPE="checkbox" NAME="caseSens">Case-sensitive<P>
<INPUT TYPE="button" VALUE="Execute match()" onClick="doMatch(this.form)">
<INPUT TYPE="reset"><P>
Result:<INPUT TYPE="text" NAME="result" SIZE=40><BR>
Count:<INPUT TYPE="text" NAME="count" SIZE=3><BR>
</FORM>
</BODY>
</HTML>



           
         
    
    
  








Related examples in the same category

1.Searching and Replacing Substrings
2.Regular Expression Tester
3.The Regular Expression Tester
4.Regular Expressions: Looking for a Match
5.Regular Expressions: Extracting Data from a Match
6.Regular Expressions: Replacing Strings via Regular Expressions
7.check Date format
8.Split comma number string
9.Use regular expression to validate url
10.String match pattern: (.*)
11.Whether a string is a valid phone number
12.String replace with regular expression
13.Finding a substring within a string
14.Whether a string contains only numerical data
15.Validate an email
16.Using regular expressions to validate an email
17.Using regular expression (callback function)
18.Split a string array and get token
19.Trim a string with regular expression from both sides
20.The Backslash in RegExp
21.Regular Expression Switch
22.Try your regular expression here