Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex to parse out substring, two options

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

    MEDevel.com: Open-source for Healthcare and Education

    Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

    Visit Medevel

  • eap-edp-reporting-prod-gcp

  • eap-edp-ingestion-nonprod-lunar

  • eap-edp-ingestion-prod-google

I would just want to extract prod/nonprod.

>Solution :

((?: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/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading