Saqib Saqib - 3 months ago 60
Python Question

Python Regular Expression example

I want to write a simple regular expression in Python that extracts a number from HTML. The HTML sample is as follows:

Your number is <b>123</b>

Now how can I extract "123", i.e. the contents of first bold text after string "Your number is"?

import re
m ="Your number is <b>(\d+)</b>",
      "xxx Your number is <b>123</b>  fdjsk")
if m:
    print m.groups()[0]