0

wont work, how to fix this problem? I need to get the number. Foo can bee with space or without space.

(?<=Foo:\s?</b>).+\d
<b>Foo:</b>2013<br><b>Bar:</b>
<b>Foo: </b>2013<br><b>Bar:</b>
atako katukas
  • 21
  • 1
  • 8

2 Answers2

2

If the engine you're using only supports 'fixed' length lookbehind assertions, you could just stack up two of them. If there could be an unknown number of spaces, this won't work.

 # (?:(?<=Foo:</b>)|(?<=Foo:\s</b>))\d+

 (?:
      (?<= Foo:</b> )
   |  (?<= Foo: \s </b> )
 )
 \d+ 
1

The problem is that variable length lookbehind are not allowed in many languages, however some languages allow to put alternatives inside:

If you don't use Python or javascript, try this:

(?<=Foo:\s</b>|Foo:</b>).+\d

If you use Perl or PHP you can do this too:

Foo:\s?</b>\K.+\d

(but the difference in this second pattern is that Foo:\s?</b> are matched and remove from the match result. Thus if you need to match these characters before you can't use this way)

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125