<SCRIPT LANGUAGE="JavaScript1.2"> |
re = /(\w+)\s(\w+)/; |
str = "John Smith"; |
newstr=str.replace(re, "$2, $1"); |
document.write(newstr) |
</SCRIPT> // Prints out Smith, John |
Suppose re is a RegExp object and str a string, then: |
function testinput(re, str){ |
if (re.test(str)) |
midstring = " contains "; |
else |
midstring = " does not contain "; |
document.write (str + midstring + re.source); |
} |
Prints out a summary of matching result |