C:\Users\dibyajyo>python
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> import re
>>> outString = 'DiagnosticPath = fs0:\\efi\\tools'
>>> print outString
DiagnosticPath = fs0:\efi\tools
>>> expString = 'DiagnosticPath = fs0:\\efi\\tools'
>>> print expString
DiagnosticPath = fs0:\efi\tools
>>> matchObj = re.search(expString, outString, re.M|re.I)
>>> if matchObj:
... print matchObj.group()
...
>>>
兩個expString
和outString
字符串相同但不知道爲什麼,我沒有找到任何匹配...蟒蛇正則表達式無法匹配反斜槓字符串參與
您是否嘗試過使用原始字符串表達式? 'expString = r'DiagnosticPath = fs0:\\ efi \\ tools'' – Felk
這正是我想嘗試後發佈的內容。遲到了31秒。 – lanenok