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)


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

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