SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Berlin
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regular expression look back

    In JavaScript you can use a 'lookahead' to match for something only if it is followed by something else:
    Code:
    /foo(?=bar)/
    matches the 'foo' in 'foobar' but not the 'foo' in 'foodstuffs.' Fine.

    How can I match the 'bar' in 'foobar' but not the 'bar' in 'Zanzibar'?

  2. #2
    SitePoint Addict
    Join Date
    Nov 2003
    Location
    Malmoe, Sweden
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately JavaScript does not support 'lookbehind'.

    Code:
    /foo(bar)/
    Will match foobar and put bar in the first substring matches array. But I bet this is not what you are looking for.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Berlin
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But I bet this is not what you are looking for.
    No, it wasn't, thanks. But never mind, I'll just do without.


Bookmarks

Posting Permissions

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