1

I am trying to write a regular expression to match the fractional portion of a street address (e.g. 123 1/2 Broadway). This is what I have:

(?<=\d+ )\d/\d

So basically match any string x/x that follows any number of digits and a space. For some reason I don't get any matches. If I remove the plus this works okay:

(?<=\d )\d/\d

... but I still don't understand why the first one wouldn't work. Thanks!

serverpunk
  • 10,665
  • 15
  • 61
  • 95
  • 3
    Which regex engine are you using? Some of them don't support variable length look-behinds. – Rohit Jain Aug 08 '13 at 20:20
  • Yes, please be more explicit about context. RegEx engine, programming language / command line utility. Code segment in the first case, exact command and options in the second, etc. – Mario Rossi Aug 08 '13 at 20:27
  • Sorry about that - this will be in JavaScript but at the moment I'm just using the search function in Sublime Text to test it out. – serverpunk Aug 08 '13 at 20:36
  • 1
    JavaScript doesn't support lookbehind at all. – Bergi Aug 08 '13 at 20:42

1 Answers1

2

Depending on your regex engine, the characters in your lookbehind have to be of fixed width. Since \d+ is not fixed width (+ means it can be 1, 2, 3, etc times), it won't work.

As for why, I think that this answer answers it well :)

Community
  • 1
  • 1
Jerry
  • 70,495
  • 13
  • 100
  • 144