Basic HTML version of Foils prepared 3 March 99

Foil 66 RegExp Objects III -- String Methods

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

Regular Expressions for Foil 66
1 String object methods have been added to JavaScript 1.2 to handle regular expressions -- consider an ordinary string ordstr
  • ordstr.search( regexp ); // like test(...)and equivalent to ordstr =~ m/regexp/ in PERL returns true or false
  • ordstr.match( regexp ); // like exec(...)and returns a results array as described for exec
  • newstr = oldstr.replace( regexp, newsubstr ); // equivalent to ordstr =~ s/regexp/newsubstr/ in PERL but returns a new string -- leaving original unchanged
2 The split(...) method now takes a regular expression as optional parameter:
  • var strArray = str.split( /\s*;\s*/ );
  • splits using ; surrounded by any whitespace characters

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