인용 하위 문자열 이스케이프 문자, 다음 두 칼 바커의와 피어스의 응답 것 모두 일치 제대로 포함되지 않은 일치하는 경우. 그러나, 두 가지의 피어스의 표현이 더 효율적입니다 :
reobj = re.compile(r"""
# Match double quoted substring (no escaped chars).
" # Match opening quote.
( # $1: Quoted substring contents.
[^"]* # Zero or more non-".
) # End $1: Quoted substring contents.
" # Match closing quote.
""", re.VERBOSE)
그러나 인용 하위 문자열이 일치 할 경우 않습니다
문자를 탈출 포함, (예를 들어, "그녀는 말했다 : \"\ 안녕 "나에게 \ n. "), 당신은 다른 표현이 필요합니다 :
reobj = re.compile(r"""
# Match double quoted substring (allow escaped chars).
" # Match opening quote.
( # $1: Quoted substring contents.
[^"\\]* # {normal} Zero or more non-", non-\.
(?: # Begin {(special normal*)*} construct.
\\. # {special} Escaped anything.
[^"\\]* # more {normal} Zero or more non-", non-\.
)* # End {(special normal*)*} construct.
) # End $1: Quoted substring contents.
" # Match closing quote.
""", re.DOTALL | re.VERBOSE)
이 내가 트릭을 할 것 알고 있어요 여러 표현이 있지만, 위의 (MRE3에서 촬영 한) 무리의 가장 효율적이다 . 이 다양하고 기능적으로 동일한 표현을 비교하는 my answer to a similar question을 참조하십시오.
나는 Karl의 대답이 내 것보다 낫다. 고마워, 칼 – Pierce