[英]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.