Basic HTML version of Foils prepared 3 March 99

Foil 77 Examples of match (string) and exec (RegExp)

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


//Match one d followed by one or more b's followed by one d
//Remember matched b's and the following d
myRe=/d(b+)(d)/ig; str = "cdbBdbsbz";
myArray = myRe.exec( str );
myArray.index Index of First Character Matched i.e. 1
myArray.input The original String i.e. cdbBdbsbz
myArray[0] The characters matched i.e. dbBd
myArray[1] The first parenthesis i.e. bB
myArray[2] The second parenthesis i.e. d
The static properties of RegExp are set including $` $& $' $1 $2 lastMatch lastParen
Properties source lastIndex multiline global ignoreCase of myRe are also set
Can also use myArray = str.match(myRe)



© 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