【发布时间】:2019-02-17 21:21:13
【问题描述】:
我是 Python 新手...
如果在谷歌上搜索几天后,我仍然无法正常工作。
我的脚本:
import re
pattern = '^Hostname=([a-zA-Z0-9.]+)'
hand = open('python_test_data.conf')
for line in hand:
line = line.rstrip()
if re.search(pattern, line) :
print line
测试文件内容:
### Option: Hostname
# Unique, case sensitive Proxy name. Make sure the Proxy name is known to the server!
# Value is acquired from HostnameItem if undefined.
#
# Mandatory: no
# Default:
# Hostname=
Hostname=bbg-zbx-proxy
脚本结果:
ubuntu-workstation:~$ python python_test.py
Hostname=bbg-zbx-proxy
但是当我在测试器中测试正则表达式时,结果是:https://regex101.com/r/wYUc4v/1
我需要一些建议,但我只能得到 bbg-zbx-proxy 作为脚本输出。
【问题讨论】:
标签: python regex python-2.7