我有一个问题,无法从我的正则表达式中获取具有空格的值。任何人都可以帮助我使用键值机制向正确的正则表达式提供。请注意,键值位置可能会更改,并且不会固定。
正则表达式
's*(['w'd_]*)=(.*?)'s+
输入
spt=38271 deviceExternalId=SUKUK node 1 dst=99.111.185.141 app=HTTPS rt=Jan 23 2013 15:30:45 deviceFacility=Packet filter msg=Connection was reset by server destinationTranslatedPort=443
我的结果
Match 1: spt=38271
Subgroups:
1: spt
2: 38271
Match 2: deviceExternalId=SUKUK
Subgroups:
1: deviceExternalId
2: SUKUK
Match 3: dst=99.111.185.141
Subgroups:
1: dst
2: 99.111.185.141
Match 4: app=HTTPS
Subgroups:
1: app
2: HTTPS
Match 5: rt=Jan
Subgroups:
1: rt
2: Jan **==>Should grab [Jan 23 2013 15:30:45]**
Match 6: deviceFacility=Packet
Subgroups:
1: deviceFacility
2: Packet **==>Should grab [Packet filter]**
Match 7: msg=Connection
Subgroups:
1: msg
2: Connection **==>Should grab [Connection was reset by server]**
Match 8: destinationTranslatedPort=443
Subgroups:
1: destinationTranslatedPort
2: 443
试试这个:
(['w'd_]+)=(.*?)(?='s+['w'd_]+=|$)
print "$1'n$2";
更简单:'s*(['w'd_]*)=([^=]+)'s+