Basic HTML version of Foils prepared 3 March 99

Foil 64 RegExp Objects I

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


An RegExp object (new in JavaScript 1.2) corresponds to a regular expression
  • Regular expressions were popular in Perl and JavaScript implementation is modeled on this version
There are two syntax's for defining regular expressions: regexp1 = new RegExp( "pattern" ); // or regexp1 = new RegExp( "pattern","flags" ); regexp2 = /pattern/flags; // no quotes
Flags are g (match to all occurences) and i (ignore case) or of course gi
The latter literal version "compiles" the pattern and is equivalent to
  • regexp2 = regexp1.compile("pattern")
  • Compilation is done for efficiency
The RegExp object has two other methods: exec(str) and test(str)and we can also invoke regular expression processing using new String object methods
There are both static (as in RegExp.input) and dynamic (as in regexp1.global) properties of regular expressions



© 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