Home > Blockchain >  Regex to parse out substring, two options
Regex to parse out substring, two options

Time:12-15

I have a list of group names that all either contain prod or nonprod inside of the name. I would like to extract out the prod or nonprod from the group name for each row. Is there a regex that could do this?

Group name examples:

  • eap-edp-refined-nonprod-adp

  • eap-edp-reporting-prod-gcp

  • eap-edp-ingestion-nonprod-lunar

  • eap-edp-ingestion-prod-google

I would just want to extract prod/nonprod.

CodePudding user response:

((?:non)?prod)

(       = Start of capture group
(?:non) = None capturing group for the literal string "non"
?       = Zero or one of "non"
prod    = The literal string "prod"
)       = End of capture group

Try it out at https://regex101.com/

  • Related