當然,這裏是你如何在Python中做到這一點。
1.py:
import re
txt='[Id][email protected],{buyerid}<>@id,[userid]>@userid,{custid}=[email protected],status>1'
re1='(.*?),' # Command Seperated Values 1
re2='.*?' # Non-greedy match on filler
re3='.*?,' # Uninteresting: csv
re4='.*?' # Non-greedy match on filler
re5='.*?,' # Uninteresting: csv
re6='.*?' # Non-greedy match on filler
re7='(.*?),' # Command Seperated Values 2
rg = re.compile(re1+re2+re3+re4+re5+re6+re7,re.IGNORECASE|re.DOTALL)
m = rg.search(txt)
if m:
csv1=m.group(1)
csv2=m.group(2)
print "("+csv1+")"+"("+csv2+")"+"\n"
2.py:
import re
txt='[Id][email protected],{buyerid}<>@id,[userid]>@userid,{custid}[email protected],status>1'
re1='.*?' # Non-greedy match on filler
re2='.*?,' # Uninteresting: csv
re3='(.*?),' # Command Seperated Values 1
re4='.*?' # Non-greedy match on filler
re5='(\\{custid\\}[email protected])' # Command Seperated Values 2
rg = re.compile(re1+re2+re3+re4+re5,re.IGNORECASE|re.DOTALL)
m = rg.search(txt)
if m:
csv1=m.group(1)
csv2=m.group(2)
print "("+csv1+")"+"("+csv2+")"+"\n"
3.py:
import re
txt='[Id][email protected],{buyerid}<>@id,[userid]>@userid,{custid}[email protected],status>1'
re1='.*?' # Non-greedy match on filler
re2='(status)' # Word 1
re3='(>)' # Any Single Character 1
re4='(\\d+)' # Integer Number 1
rg = re.compile(re1+re2+re3+re4,re.IGNORECASE|re.DOTALL)
m = rg.search(txt)
if m:
word1=m.group(1)
c1=m.group(2)
int1=m.group(3)
print "("+word1+")"+"("+c1+")"+"("+int1+")"+"\n"
有辦法做到這一點沒有正則表達式。你在用什麼語言? –
請詳細說明條件。向我們展示其他一些例子。邊緣案例呢?任何例外? ...更重要的是,你到目前爲止嘗試過什麼? – Mariano
要考慮的具體邊緣情況:包含逗號的字段,包含引號的字段。 – Richard