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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -