Python regex findall numbers and dots

前端 未结 1 1512
没有蜡笔的小新
没有蜡笔的小新 2021-02-08 14:54

I\'m using re.findall() to extract some version numbers from an HTML file:

>>> import re
>>> text = \"
1条回答
  •  囚心锁ツ
    2021-02-08 15:14

    re.findall(r"Test([0-9.]*[0-9]+)", text)
    

    or, a bit shorter:

    re.findall(r"Test([\d.]*\d+)", text)
    

    By the way - you do not need to escape the dot in a character class. Inside [] the . has no special meaning, it just matches a literal dot. Escaping it has no effect.

    0 讨论(0)
提交回复
热议问题