Home > Enterprise >  Match folder in URL path but exclude parameters
Match folder in URL path but exclude parameters

Time:07-07

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.

Any help would be appreciated

CodePudding user response:

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
  • Related