совпадение с двумя необязательными опережающими поисками - PullRequest
1 голос
/ 25 мая 2020

Пусть в конце абзаца могут быть две строки. Абзац может не иметь окончаний, иметь только одно окончание или иметь оба окончания в любом порядке. Моя задача - захватить абзац, продолжая любую возможную комбинацию окончаний.

For this example. suppose,

the first ending is “I’m so glad to be home again!” and 
the second ending is "After all, tomorrow is another day."

Some Examples:
String: "This is well-told story. After all, tomorrow is another day."
Match: "This is well-told story."

String: "A story with no end."
match: "A story with no end."

string: "A children's story. I’m so glad to be home again! After all, tomorrow is another day."
match: "A children's story."

string: "Another sentence in a Romance novel. I’m so glad to be home again!
match: "Another sentence in a Romance novel"

I tried:

    .*(?=“I’m so glad to be home again)(?=After all, tomorrow is another day)

but it doesn't work for all scenarios.  Thanks!

1 Ответ

0 голосов
/ 25 мая 2020

Попробуйте:

(contents. )((first ending)|(second ending))*

См .: https://regex101.com/r/lb098N/1

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...