RegEx match before string or all / Remove string from match -
i tried search not find case. need match before string "part 1" or "part 2" etc. in case there not "part x" string match all. example:
- any words here part 1
- any words here part 2
- any words here
it should return "any words here". have tried
(.+)(?=\spart\s\d|\spart\s\d)
but not match when "part x" missing. other solution remove "part x" string match.
thank help!
^.+?(?=part\s*1|part\s*2|$)
use anchors
ored part 1
, part 2
.see demo.
https://regex101.com/r/cz0sd2/5
or
^.+?(?=part\s*\d+|$)
Comments
Post a Comment