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

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -