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 match only part of a path

Hi I want a regex to match everything here except the last 4. path1, path2 and $VAR or ${VAR} are fixed values

I don’t want to match any subpaths of these like the last 4.

value=/path1
value=/path2
value=/path1/
value=/path2/
value=${VAR}
value=${VAR}/
value=$VAR
value=$VAR/

value=/path1/foo
value=/path2/foo
value=${VAR}/foo
value=$VAR/foo

I came up with this but it doesn’t seem to work on ${VAR}

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

^value=(\/(path1|path2)|\\${VAR})\/?$

(see https://regex101.com/r/EwRuab/1)

>Solution :

This regex, no need to double backslash $:

^value=(/(path1|path2)|\$VAR|\${VAR})/?$

Online Demo

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