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

How to select a part of a string in a set, but not the string exactly in RegEx

I am trying to select part of a URL /example/privacy-policy and /example/123/privacy-policy but not /privacy-policy

I currently have this ^[^\/privacy\-policy].\/privacy\-policy.$

But it seems to not work still. Ideally, it would be able to find privacy-policy anywhere in the string without directly matching the root /privacy-policy

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

Thank you very much!

>Solution :

If you don’t want privacy-policy as the root of your url, but you still want to match it, you can force the regex to look for at least one more symbol before the backslash that preceeds privacy-policy:

(.+\/)privacy-policy

Then if you want to get the part that comes before privacy-policy, you can reference Group 1.

Is this what you’re looking for?

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