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 4 of 4
  1. #1
    Senior Coder
    Join Date
    Feb 2003
    Location
    Ontario, Canada
    Posts
    1,223
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Requesting a RegExp...

    I posted something pretty much the same in the "server side" forum, but realised that the JS folks might have more experience with this:

    I'm simply looking to match "wordhere/" (ignore all my double quotes) where "wordhere" does not equal "admin" or "register". So this would be something like:

    [^(admin|register)]+[\/]?

    The trailing slash may or may not be there.

    EDIT: Oh, and the "wordhere" needs to be captured. That's the trouble right there. Capturing the bugger is proving difficult.

    Anyway, this doesn't work. Any ideas?

    Thanks a whole heap in advance.
    Last edited by AaronW; 10-05-2003 at 04:17 PM.

  • #2
    Regular Coder
    Join Date
    Sep 2003
    Posts
    290
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    /^(?!admin|register)(.*)\/$/i

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Negative lookaheads are not the best supported feature of JS regexes. Why not do a two-stage confirmation instead?
    Code:
    var
        r=(/^(admin|register)/i).test([string path])?
            null:
            (/^([^\/])/i).match([string path]);
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    Senior Coder
    Join Date
    Feb 2003
    Location
    Ontario, Canada
    Posts
    1,223
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, I went with liorean's approach.

    I got really close with a few of my own. Annoying that something this easy took me so long


  •  

    Posting Permissions

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