View Full Version : Reg Exp in mozilla

08-25-2004, 05:26 PM
Why does this function give mozilla problems:

function getAName()
var path = document.addname.aphoto.value;
var file = path.match(/[^/\\]+$/);

document.addname.addphoto.value = file

Error: unterminated character class ^
Source Code:
var file = path.match(/[^/\\]+$/);

is the error I get. I works in IE but not moz. All help is appreciated, thanks.

08-25-2004, 05:34 PM
Well the character class is the bit between the []'s. I suppose the final backslash could be escaping the ending square bracket, but you've escaped the backslash with a backslash so I don't really know :confused:

08-25-2004, 05:38 PM
Ah, sorry. Took one more look and realized what it was! The regex enterpreter sees the forward slash in the middle and thinks it is the ending delimeter for the expression. You need to escape it...


Willy Duitt
08-25-2004, 05:43 PM
The pattern as written does not make much sense to me...
What it says is to match everything except / and \....
And I would think that if you are checking a file path that you would be checking for those characters... Not, not checking for them...

And BTW: \e is the same as \\....


08-25-2004, 06:16 PM
thanks fellas, your help is appreciated