あなたのリンクから、テキストは次の規則に従っているようです。
- 各「行」は厳密な意味での行です。つまり、 で区切られてい
\n
ます。
- 段落は、2 つ以上の連続する改行 (_i.e.) によって区切られます。
\n\n+
.
'
スピーチを区別するために、無方向の一重引用符のみが使用されます。
ここに簡単な試みがあります (一番下までスクロールして、マッチ グループを表示します) — 間違っていると思います — しかし、正しい方向に導くのに十分な情報がここにはあります。$1
慣用的に、$2
、および$3
、「言った」セパレータ間の句読点を含む各文字のスピーチを取得する方法に注意してくださいただし、言語の特定の癖がこの正規表現をどのように無効にするかに注意してください。たとえば、段落の終わりで引用符を閉じずに、スピーチが次の段落に続く場合に新しい引用符を開くという事実は、全体のバランスを崩します-戦略を引用し、アポストロフィも同様です。
\n\n.*?'([^^]+?[?]?),?' said (?:[A-Z][a-z]+)(?:([.]) |, )'([^^]+?)'(?=[^']*(?:'[^']')*[^']*\n\n.*'(?:[^^]+?[?]?),?' said (?:[A-Z][a-z]+)(?:[.] |, ))
| | | <----><--> <>|<-------------------><------------>| <----> |<--------------------------------------------------------------------------------->
| | | | | | || | | | ||
| | | | | | || | | | |assert that this end-quote is followed by a string of non-quote characters, then
| | | | | | || | | | |zero or more strings of quoted non-quote characters, then another string of non-
| | | | | | || | | | |quote characters, a new paragraph, and the next "said Bernard"; otherwise fail.
| | | | | | || | | | |
| | | | | | || | | | match an (end-)quote
| | | | | | || | | |
| | | | | | || | | match any character as needed (but no more than needed)
| | | | | | || | |
| | | | | | || | match a (start-)quote
| | | | | | || |
| | | | | | || match either a period followed by two spaces, or a comma followed by one space
| | | | | | ||
| | | | | | |match the "said Bernard"
| | | | | | |
| | | | | | match an (end-)quote
| | | | | |
| | | | | match a comma, optionally
| | | | |
| | | | match a question mark, optionally
| | | |
| | | match any character as needed (but no more than needed)
| | |
| | match a (start-)quote
| |
| match as many non-newline characters as needed (but no more than needed)
|
new paragraph
Rubular マッチ (抜粋):
Match 3
1. But when we sit together, close
2.
3. we melt into each
other with phrases. We are edged with mist. We make an
unsubstantial territory.
Match 4
1. I see the beetle
2. .
3. It is black, I see; it is green,
I see; I am tied down with single words. But you wander off; you
slip away; you rise up higher, with words and words in phrases.