JavaScript 1.2 (found in Netscape 4.0, Internet Explorer 4.0, and Opera 5.0) allows the use of regular expressions, with a few twists.

The most annoying twist is that you can only follow your regexp with i (case insensitive) and/or g (global search) operators. e, m, o, s, and x are all unavailable, in any browser. This is generally because of limitations imposed by the JavaScript language itself, typically because it lets you end any line with a newline instead of a semicolon.

The absense of e (evaluate before matching) is the most annoying, since this allows you to assemble your pattern dynamically. In Perl, if you had a variable $vari which a user could modify, the pattern /$vari/eg would match every occurence of whatever string $vari contained. Fortunately, JavaScript has a workaround.

A regular expression is treated like an object in JavaScript, and one can be assembled dynamically by feeding a pair of strings to a RegExp constructor. If you don't need a dynamic expression, you can feed it directly to a function, such as:

  str = str.replace(/sue/g, "bob");
If you had a variable string in JavaScript named vari, then
  reg = new RegExp(vari, "g");
will produce a regular expression to match every occurence of vari in a string, and
  str = str.replace(reg, "bob");
would replace every occurence of it in the string str with "bob".

This recently came in handy when I was writing some JavaScript pattern matches for an EDev document and discovered that my need for brackets inside the regular expression made E2 try to add hardlinks in the middle of my code. So instead of

  match = str.replace([aeoiu], "y");
I would do the following:
  ob = String.fromCharCode(91);    // opening bracket
  cb = String.fromCharCode(93);    // closing bracket
  reg = new RegExp(ob+"aeiou"+cb, "g");
  str = str.replace(reg, "y");

A bit of a kludge, but it gets the job done.