Basic HTML version of Foils prepared 3 March 99

Foil 76 Examples of Replace and test

From Overview of JavaScript I -- Basic Web Scripting Language CPS616 Technologies of the Information Age -- Spring Semester 99. by Geoffrey C. Fox (Tom Scavo)


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

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Mar 3 1999