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,133
  • 14
  • 58
  • 92

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
  • 68,613
  • 12
  • 97
  • 138