Hi! I think, m{path/(\w+)?/?$} regex can solve your problem.
In general, to parse URL, you can use official regex from rfc3986 (see Appendix B for rfc3986)
regex is ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? $2 is protocol $4 is host $5 is path $7 is query $9 is fragment. Another approach is to use some of cpan modules to parse URI. For example, https://metacpan.org/pod/URI On 7/17/18 2:56 PM, Lauren C. wrote:
Hello, I want to match: /path/ /path/123 /path/abc but /path/?xxx should not be matched. This works: $ perl -le '$x="/path/abc"; print 1 if $x=~m{path/\w+}' 1 this works too: $ perl -le '$x="/path/?abc"; print 1 if $x=~m{path/\w+}' But it doesn't work for this case: $ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}' it expects 1 returned. Can you help? thanks.