Saqib Saqib - 1 year ago 145
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"?

Answer Source
import re
m ="Your number is <b>(\d+)</b>",
      "xxx Your number is <b>123</b>  fdjsk")
if m:
    print m.groups()[0]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download