-2
의 측면 []에서 정규 표현식 안녕하세요, 저는 파이썬 스크립트이므로 잘 작동하는 나머지 코드에서 정규 표현식을 얻기 위해 고심하고 있습니다. 파이썬 코드
이
내 코드입니다 :import re
with open("nfile.cli") as f:
newlist = f.read()
cmd = re.search(r'^\W(command=)(".*?")', newlist)
if(cmd == None):
print cmd
else :
newstr = cmd.group()
print newstr
argument = re.search('<.*>', newstr)
print argument.group()
option = re.findall("{.*}", newstr)
print option
kword = re.search('[.*?]', newstr)
print kword.group()
출력 : 내가 좋아하는 읽고 싶은
%command="[enable | disable] port <port-no> {force}"
<port-no>
['{force}']
Traceback (most recent call last):
File "read_command.py", line 16, in <module>
print kword.group()
AttributeError: 'NoneType' object has no attribute 'group'
nfile:
%command="[enable | disable] port <port-no> {force}"%
: [수 | 해제]
감사
당신은 말할 필요가 없습니다 당신의 인생 이야기 제목. – Maroun
대괄호는 Python의 정규 표현식 구문 (http://docs.python.org/2/library/re.html#regular-expression-syntax)에서 문자 클래스를 나타내는 데 사용됩니다. – amitparikh
사이드 노트 ...'if cmd is None :'대신'if cmd == None :'을 사용하십시오. – SethMMorton