Search code examples
regexnginxslug

Nginx Regex - Matching Slug


I have a slug like this

/my-product-group-any-name/my-product-name-just-name/1500

I'm trying to make nginx location matching with my regex to match that slug, currently my regex is like this

^\/([a-z0-9]+((-)+[a-z0-9]+)*)*

when I'm trying to add backslash it throw error (I tested on Rubular.Com). I'm still consfused on how to match that slug. Any help appreciated


Solution

  • The following regex should solve your problem.

    ^(\/([a-z0-9]+((-)+[a-z0-9]+)*))*
    

    You've missed additional round brackets for the slashs in combination with the alpha-numeric-string