...

View Full Version : Reg Exp in mozilla



ecnarongi
08-25-2004, 04: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
document.addname.submit()
}

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.

trib4lmaniac
08-25-2004, 04: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:

trib4lmaniac
08-25-2004, 04: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...

path.match(/[^\/\\]+$/);

Willy Duitt
08-25-2004, 04: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 \\....

.....Willy

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum