Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Northern NJ
    Posts
    404
    Thanks
    0
    Thanked 1 Time in 1 Post

    Reg Exp in mozilla

    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.
    I would rather be a lion for a day than a lamb that lives forever.

  • #2
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...
    Code:
    path.match(/[^\/\\]+$/);

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Northern NJ
    Posts
    404
    Thanks
    0
    Thanked 1 Time in 1 Post
    thanks fellas, your help is appreciated
    I would rather be a lion for a day than a lamb that lives forever.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •