0

I have a requirement to parse part of url with multiple expressions using regex, expressions are like /abc/def (or) /z/a (or) /v/g. I have a regex that satisfies single expression, but not sure how to do for multiple expression.

(?<volga>.+?\/abc\/def.+?)

volga is a named capturing group. Above regular expression satisfies anything before /abc and anything after /def, the same way url also has /z/a and /v/g. This is kind of either /abc/def/ or /z/a or /v/g can exist in url. How to write a regular expression that checks for all of above expressions.

Examples of url:

/api/com/abc/def/710660716/847170/
/api/com/z/a/
Barmar
  • 741,623
  • 53
  • 500
  • 612
Vipul
  • 545
  • 1
  • 8
  • 30

1 Answers1

1

Maybe this:

(?<volga>.+?\/((abc\/def)|(z\/a)|(v\/g)).*)
  • Matches any string containing
    • abc/def
    • or z/a
    • or v/g

Regex101

degant
  • 4,861
  • 1
  • 17
  • 29