这是我的代码:
#!/usr/bin/python
import io
import re
f = open('/etc/ssh/sshd_config','r')
strings = re.search(r'.*IgnoreR.*', f.read())
print(strings)
Run Code Online (Sandbox Code Playgroud)
返回数据,但我需要特定的正则表达式匹配:例如:
^\s*[^#]*IgnoreRhosts\s+yes
Run Code Online (Sandbox Code Playgroud)
如果我将代码更改为:
strings = re.search(r'^IgnoreR.*', f.read())
Run Code Online (Sandbox Code Playgroud)
甚至
strings = re.search(r'^.*IgnoreR.*', f.read())
Run Code Online (Sandbox Code Playgroud)
我什么都没收到.我需要能够在perl中使用真正的正则表达式