0

Is it possible to match based on something similar to && conditions? On the following URL, I see how we can use the | annotation for an Or, where it will match if either are true but what about if multiple are true?

https://www.mikesdotnetting.com/article/44/vbscript-regular-expressions-cheat-sheet

For instance, lets say I have the following strings

"SuperItem_BoxA" "Super_ItemBoxB"

and I want a regular expression to return Super_ItemBoxB using logic like

if string contains 'Item' && 'Super' && 'BoxB'

If I were to do "Super|Item|BoxB" it will return both of these since they are or conditions.

1
  • 1
    Don't you want to extract words? Why use regex if you just can check for 3 substrings in a string with InStr? Apr 12, 2019 at 19:05

2 Answers 2

2

You may use

\b(?=\w*Super)(?=\w*Item)(?=\w*BoxB)\w+

enter image description here Details

  • \b - a word boundary
  • (?=\w*Super) - the word must contain Super
  • (?=\w*Item) - the word must contain Item
  • (?=\w*BoxB) - the word must contain BoxB
  • \w+ - consume 1+ word chars.
1

Try this regex

(?i)super.*?item.*?boxb 
1
  • 2
    Please do not add superfluous text to work around the minimum answer length. If your answer is too short, try adding a description of your code instead. Apr 12, 2019 at 18:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.