정규식을 사용하여 여러 줄 패턴을 검색하는 데 문제가 있습니다.multiline regex
다음some command [first line]\n
second line \n
yes can have multiple lines\n
\n
something else that I do not care about.
내가 지금까지 시도 무엇인가 : 다음은 샘플 여러 줄 문자열입니다
>>> match = re.match(r"^(.+)\n((.*\n)*)\n",body,re.MULTILINE)
>>> match.groups()
('some command [first line]', 'second line \nyes can have multiple lines\n', 'yes can have multiple lines\n')
내가 match.group (1) match.group를 찾고 있어요 (2), 그리고 그 (것)들과 함께 행복하지만, 나는 내가 기대하지 않는 match.group(3)
을 얻는다는 것을 나를 괴롭 히고있다. (그리고 나의 정규 표현식이 옳지 않다는 것을 나를 이렇게 만든다.)
또한, 나는 내가 Python Regular Expressions from Google 통해 갔다 ..
match = re.match(r"^(.+)\n((?P<bd>.*\n)*)\n",body,re.MULTILINE)
>>> match.group(bd)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'bd' is not defined
바로 패턴을 이름을 얻을하지 않는 것,하지만 난 아직 완전한 그림을 확보하지 않은 것은 분명하다.