[英]Response of a regular expression search Python
我试图工作一个应该与正则表达式匹配的python脚本,该乘积产生的对象始终是一个空字符串,因此我认为我在使用正则表达式时没有必要的知识。 有人可以帮忙吗? 下面是代码:
def storecheck(text, store):
res =""
for line in text.splitlines():
print str(store)
if re.search('/'+str(store)+',/g', line):
print re.search('/'+str(store)+',/g', line)+';'
res+= line
return res
“存储”在脚本中具有整数值。 我已经在python的官方网站上阅读了re.match和re.search的手册,但是只要在线测试人员不是一个幻想,这个正则表达式就应该匹配。 所以有人看到我在做什么错吗?
Python不需要定界符...,如果要进行全局搜索,可以使用re.findall
。 也许您打算这样做?
def storecheck(text, store):
res = ""
for line in text.splitlines():
print str(store)
if re.search(str(store), line):
print ';'.join(re.findall(str(store), line))
res += line
return res
我对python自己还是很陌生。 可能会有更好的方法来做同样的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.