Python Regular Expression example

前端 未结 9 1517
天命终不由人
天命终不由人 2020-12-08 10:04

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 123
         


        
9条回答
  •  借酒劲吻你
    2020-12-08 10:22

    import re
    x = 'Your number is 123'
    re.search('(?<=Your number is )(\d+)',x).group(0)
    

    this searches for the number that follows the 'Your number is' string

提交回复
热议问题