Vipul
Vipul

Reputation: 610

regex parse multiple expressions

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/

Upvotes: 0

Views: 358

Answers (1)

degant
degant

Reputation: 4981

Maybe this:

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

Regex101

Upvotes: 1

Related Questions