RegExp Objects III -- String Methods
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 PERLreturns 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
The split(…) method now takes a regular expression as optional parameter:
- var strArray = str.split( /\s*;\s*/ );
- splits using ; surrounded by any whitespace characters