Reputation: 816
I would like to validate a url against a pattern. this is the URL
/search?name=john
Now, john
could be any name, so it can be any sting. But, the/search?name=
part of the URL should remain the same always.
I tried this regex and it did not work for me.
^([/search\\?name])=([a-z]+)$"
Upvotes: 1
Views: 469
Reputation: 72844
Remove the square brackets []
around the string /search\\?name
. The brackets are used to define character classes. An expression of the form [abc]
would not match the string abc
, but only either of the characters a
, b
or c
. Hence the regex should be:
^(/search\\?name)=([a-z]+)$
There's also no need for parentheses unless you're capturing subpatterns in groups:
^/search\\?name=[a-z]+$
Upvotes: 1