PHP modify RegEx -


i have pattern:

/^(?:{?[a-z0-9\-_]+\??}?\/)+$/ 

now these strings match pattern

user/1/modify/ user/{id}/modify/ user/{id?}/modify/ 

it's ok, pattern match

user/{id?/modify/ 

if left curly brace start must end right. tried lookahead dont't know right way.

this should work:

^(?:(?:{\w+\??}|\w+)\/)+$ 

https://regex101.com/r/yo3pa5/1

it tries match in set [a-za-z0-9_] followed optional ? inside {}s, , tries match same set without {}s (and optional ?, can add in), followed /. way won't allow unclosed braces.


Comments