I read some tips, if add ?
can match the non-greedy regex like,
x = "a (b) c (d) e"
re.search(r"\(.*?\)", x).group()
>>> '(b)'
why my code cannot work?
import re
item = "等" #item is variable
content = "大数据,人工智能,云计算:数字孪生、5G,物联网和区块链等新一代数字技术应用"
res = re.search(r'(?<=[,,:、,])(.*?)(?=' + item + ')', content).group()
print(res)
I want to find the content in the middle of any cloest symbols(left) and item
(right), and I hope the res like
物联网和区块链
but it return long one, non-greedy didn't work, why?