0

I have a strings for example

Apple_Banana_Orange_PACK101_10
Pear_Apple__Grapes_BUNDLE222_06

I need a regex string that will match everything before _PACK or _BUNDLE and nothing else.

So for example I want the first string to return

Apple_Banana_Orange

I have tried:

If you're looking to capture everything up to "abc":

/^(.*?)(_PACK|_BUN)/

And a few other options but still struggling. Any help appreciated

2
  • What language are you using ? Commented Apr 10, 2019 at 13:55
  • In you pattern you are using 2 capturing groups and you already have your match in the first capturing group. See it on regex101 Commented Apr 10, 2019 at 20:21

2 Answers 2

1

Use Positive Lookahead as follows:

^.*?(?=_PACK|_BUN)

Demo

Sign up to request clarification or add additional context in comments.

Comments

0

You can simply do

^(.*)(_PACK|_BUNDLE) 

where group 1 is what you want to catch

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.