I have text like this:
Some guy writes: some content.
Some guy said: some content.
(said | writes):. *
Some guy writes: blablabla, said: some content
Prepend the regex you have with
^.* and capture it:
See the regex demo
.* will grab the whole line (or string if DOTALL modifier is used) and will backtrack to accommodate for
writes: that are the last on the string/line.
The non-capturing group in
(?:said|writes) is used for grouping only purposes, so that there is only one capturing group with ID = 1.
^- start of string/line anchor (depends on the modifiers used)
.*- any 0+ chars as many as possible (as
*is a greedy quantifier) (other than line break symbols if DOTALL modifier is not used)
((?:said|writes):.*)- Group 1 capturing:
:- a colon
.*- any 0+ chars (other than line break symbols if DOTALL modifier is not used) up to the end of line/string.