我正在从 regex 中提取此文本,我在文本中匹配了所需的字符串,但是在使用 python re 提取那些匹配的文本时,它没有提取 .
这是我正在使用的代码。
import re
PRICE = '\b(price|rs)?\s*(\d+[\s\d.]*\s*?(pkg|k|m|
(?:la(?:c|kh|k)|crore|cr)s?|l)\b\.?)'
content ='This should matchprice 5.6 lacincluding price(i.e price
5.6 lac) and rs 56 m. including rs (i.e rs 56 k rs 56 m) .
It will match normally if there is no price or rs written for example
or 56 k or 8.8 crs. are correct matching.
It should not match5.6 lac (Should not match eitherrs 6 lac asas
there is no spaces before 5.6'
for m in re.finditer(PRICE,content,pat.FLAG):
matched = m.group().strip()
print ("In matched "+ matched)`
上面的代码不会进入 for 循环。任何线索高度赞赏。谢谢。
牧羊人nacy
相关分类