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

Match folder in URL path but exclude parameters

I’m trying to match URLs using the folder path /c/ but exclude and URL with the same folder path containing a parameter. There are a lot so the parameter exclusion need to be for all or a wildcard solution.

For example

| URL | Regex Result |
| -------- | -------------- |
| https://www.example.com/c/apples/pears    | include|
| https://www.example.com/c/apples/pears?sort=low   | Exclude|
| https://www.example.com/c/apples/pears?taste=sweet   | Exclude   |

I’m trying to achieve this in Google Search Console, so it would need to be in the Re2 syntax.

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

Any help would be appreciated

>Solution :

I’m not sure the particulars of re2, but here you go:

^https://www.example.com/c/[^?]*$

Translation:

  • ^ starting at the start of the string
  • https://www.example.com/c/ Match this exact string
  • [^?]* match any number of characters which are NOT a question a mark
  • $ match all the way to the end of the string
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