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' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -