I would like to validate true for the following URLs.
$a = '/foo-bar-tar';
$b = '/foo-&-tar2';
$a = '/foo-bar-tar.';
$a = '/foo-bar.[tar]';
$a = '/foo-bar-tar';
All in all, these are the characters I am willing to accept, in no special order:
/ - & [ ] ( ) .
And of course letters and numbers:
a-z A-Z 0-9
The problem is that I can validate letters, numbers, and special characters like /.-
, but I am having trouble validating ()[]
– I guess because these are part of the regex language.
Here is the pattern I have so far:
^(/[a-z-A-z-0-9.]+)$
It matches letters, numbers, and .
, but I don't know how to make it work for ()[]
.