想要使用正则表达式从给定的文本中查找特定的字符串

时间:2019-04-15 06:53:00

标签: python regex

我希望使用正则表达式从文本下方输入特定的字符串。

str = 'Supervision68 - Outdoor Supervision In Compliance922 KAR 2:100 - 
Section 10(15) Each child'

特定字符串:“ 68-符合户外监督规定”

我尝试获得以下结果:

re.findall('\d+(.*?)922', str)

结果:“-合规性户外监督”

1 个答案:

答案 0 :(得分:0)

您几乎拥有它:

import re
str = 'Supervision68 - Outdoor Supervision In Compliance922 KAR 2:100 - Section 10(15) Each child'
print(re.findall('(\d.*?)922', str))

输出

['68 - Outdoor Supervision In Compliance']