Everything after a Keyword
We can deal with the unwanted punctuation by using w
to eat up all non-unicode.
sentence = "Hearsay? With masked flasks I said: abracadabra"
keys = '|'.join(['ask', 'asks', 'asked', 'say', 'says', 'said'])
result = re.search(rf'({keys})W+(.*)', sentence, re.S | re.I)
if result == None:
print(sentence)
else:
print(result.group(2))
Output:
abracadabra
case-sensitive: You have case-insensitive flag re.I
, so we can remove Say
permutation.
multi-line: You have re.M
option which directs ^
to not only match at the start of your string, but also right after every
within that string. We can drop this since we do not need to use ^
.
dot-matches-all: You have (?s)
which directs .
to match everything including
. This is the same as applying re.S
flag.
I'm not sure what the net effect of having both re.M
and re.S
is. I think your sentence might be a text blob with newlines inside, so I removed re.M
and kept (?s)
as re.S
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…