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)


1 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
2 There are two syntax's for defining regular expressions: regexp1 = new RegExp( "pattern" ); // or regexp1 = new RegExp( "pattern","flags" ); regexp2 = /pattern/flags; // no quotes
3 Flags are g (match to all occurences) and i (ignore case) or of course gi
4 The latter literal version "compiles" the pattern and is equivalent to
  • regexp2 = regexp1.compile("pattern")
  • Compilation is done for efficiency
5 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
6 There are both static (as in RegExp.input) and dynamic (as in regexp1.global) properties of regular expressions

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