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

Diane Soini dianesoini at earthlink.net
Fri Feb 18 20:11:30 CST 2005


On Friday, February 18, 2005, at 04:06 AM,  
thelist-request at lists.evolt.org wrote:
>
> On Thu, 17 Feb 2005 20:22:41 -0800, Diane Soini
> <dianesoini at earthlink.net> wrote:
>> 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.
>
> Do you have some examples?
>

A real simple example, which doesn't have to be done with regexp:

URL.split(/javascript:/);

In Firefox: [,"popup('foo.html')"]
In IE6: ["popup('foo.html')"]

Will I always get a null value for the first array item in FF using  
String.split(regexp)?


In a more complicated example (which I don't have in front of me)

var pattern =  
/(support).+\/ 
(collections|concepts|mfgx|public|qbits|services|solution_center|support 
)(\/[^\/]+)(\/[^\/]+)*/;

I am trying to see if the URL is in one of those folders  
(collections...) then what is the next folder, and if there is one or  
more folders below that, then that/those, too. In the end, I will  
process these three results to show a report:

Category
Sub-category
Sub-sub category (optional) + document title

Using URL.exec(pattern) the results were too variable among browsers  
for me to capture the second, third, and last bit in the parens. So I  
think I'm using URL.match(pattern) instead. That may also be  
problematic, too. I just don't have much faith in regexp for this now.

So, what would be a better approach? There are not consistent levels of  
folders. I suppose I could just split on the '/' and write tons and  
tons of if-else statments...but that just seems so ugly and hard to  
maintain.




More information about the thelist mailing list