我正在尝试使用python正则表达式匹配'['
和'] '
之间的所有字符(请注意额外的空格)。最初我与天生匹配([^])
然后消耗了空间,但在我的一个测试用例中有]
个字符。我的示例字符串是
127.0.0.1 - dgm [Thu Oct 2 09:55:11 2014] [9 <?xml version="1.0"?><action><signal><composite id="1" data="atm_te" format="generic" exp_number_start="12000" exp_number_end="0" pass_start="-1" pass_end="-1"><composite_dim dimid="0" dim="atm_r" to_dim="0" format="generic" /></composite><documentation id="1" exp_number_start="12000" exp_number_end="0" pass_start="-1" pass_end="-1"><description>YAG TS Te Profile</description><label>Te</label><units>[eV]</units><dimension dimid="0"><label>Major Radius</label><units>[m]</units></dimension><dimension dimid="1"><label>Time</label><units>[s]</units></dimension></documentation></signal></action> 13500 0 0 XML MAST MAST ] 0 20872 [] 44.909000 6 6 [25837 7417]
所以我尝试使用正则表达式使用前瞻
(?P<host>\s|\S+)\s?- (?P<username>\s|\S+)\s?\[(?P<datetime>[^]]*)\]\s\[(?P<query>.*(?=\]\s))\]\s
但这似乎在我的代码和pythex网页中都超支。
我正在寻找的查询组的结果是
"9 <?xml version="1.0"?><action><signal><composite id="1" data="atm_te" format="generic" exp_number_start="12000" exp_number_end="0" pass_start="-1" pass_end="-1"><composite_dim dimid="0" dim="atm_r" to_dim="0" format="generic" /></composite><documentation id="1" exp_number_start="12000" exp_number_end="0" pass_start="-1" pass_end="-1"><description>YAG TS Te Profile</description><label>Te</label><units>[eV]</units><dimension dimid="0"><label>Major Radius</label><units>[m]</units></dimension><dimension dimid="1"><label>Time</label><units>[s]</units></dimension></documentation></signal></action> 13500 0 0 XML MAST MAST "
(是的,尾随空格很重要)