[thelist] Re: differences in javascript regexp among browsers?

Diane Soini dianesoini at earthlink.net
Thu Feb 17 22:22:41 CST 2005

On Thursday, February 17, 2005, at 04:02 AM,  
thelist-request at lists.evolt.org wrote:
> On Wed, 16 Feb 2005 19:36:19 -0800, Diane Soini
> <dianesoini at earthlink.net> wrote:
>> I'm really getting bummed out by the differences in how browser do
>> certain regular expression and string functions in javascript. I seem
>> to get different results from regexp.exec(string) and
>> string.split(regexp) in different browsers. Some browsers return more
>> items in the array than others.
> Often times this is because you're relying on features that are not
> implemented in the browser that gives the least number of elements.
> Regex in JavaScript is a pretty recent feature. Things such as the
> multiline flag, non-greedy quantifiers, lookaheads, replace with
> callback functions and correct splitting of strings when the patterns
> use captured subpatterns were not supported in ie5 or nn4.
>> Any suggestions on the best way to find and extract matches on  
>> strings,
>> split strings, etc that don't cause unexpected problems?
> Avoid the features I mentioned above. Always test in saf (or any other
> KJS/KHTML browser), ie5, ie6w, moz or recent op before use. Of the
> mentioned browsers, ie5 is the one that have most problems. Ie6w and
> saf aren't problem free either, though. An example:

Well, what I have been doing is pretty simple stuff. Just split on a  
simple pattern, or match a relatively simple pattern. But the array  
returned is of different lengths in different browsers.

You say IE5 has the most problems. Well, if you use IE6 with an invalid  
or no doctype are you in effect using IE5?

So, is there an alternative or a best practice for using these regexps  
in a way that returns results more uniformly?

> Since you might find yourself interested in it, my article on regex in
> JavaScript:
> <uri:http://evolt.org/article/Regular_Expressions_in_JavaScript/17/ 
> 36435/>
> // David
> -- 
My BF's job went to China so he opened a T-shirt store:

More information about the thelist mailing list