Python, , , re . Python Matthew Barnett stellar regex, Perl, PCRE .NET.
, , re, regex, . , , regex , , Perl PCRE.
, , ( , ). : , . .
import regex
quote = regex.compile(r'''(?x)
(?(DEFINE)
(?<qmark>["']) # what we'll consider a quotation mark
(?<not_qmark>[^'"]+) # chunk without quotes
(?<a_quote>(?P<qopen>(?&qmark))(?¬_qmark)(?P=qopen)) # a non-nested quote
) # End DEFINE block
# Start Match block
(?&a_quote)
|
(?P<open>(?&qmark))
(?¬_qmark)?
(?P<quote>(?&a_quote))
(?¬_qmark)?
(?P=open)
''')
str = """'Well, I have tried to say "How Doth the Little Busy Bee," but it all came different!' Alice replied in a very melancholy voice. She continued, 'I will try again.'"""
for match in quote.finditer(str):
print(match.group())
if match.group('quote'):
print(match.group('quote'))
'Well, I have tried to say "How Doth the Little Busy Bee," but it all came different!'
"How Doth the Little Busy Bee,"
'I will try again.'
-, , , I'll I will, . I'll , .
(?(DEFINE)...) qmark, not_qmark a_quote, , .
:
(?&a_quote) ,| ...(?P<open>(?&qmark)) open,(?¬_qmark)? , ,(?P<quote>(?&a_quote)) quote,(?¬_qmark)? , ,(?P=open) , .
Python quote, .
? . (?(DEFINE)...) , , .
, .
, , , . , 1, (?1). something, (?&something). , (?) .