Reputation: 1186
I tried the pattern below with a lot of variations of (
)
and [
]
but I couldn't achieved my aim.
$pattern = '/^http:\/\/www.mydomain.p.ht\/?[\p{L}\p{N}\-]{0,36}\/?[\p{L}\p{N}\-]{0,51}\/?[\p{L}\p{N}\-]{0,101}$/';
My aim is: to match my needed url structure
http://www.mydomain.p.ht
/
slash character/
slash character/
slash character/
slash character at the very end.currently http://www.mydomain.p.ht/1234561-234561234561234-56123456123456şğ
matches but it shouldn't since 1234561-234561234561234-56123456123456şğ
part has more than 36 characters.
Can you please correct my pattern?
Upvotes: 1
Views: 244
Reputation: 956
Just correcting the regex itself
/^http:\/\/www.mydomain.p.ht(\/|\/[\p{L}\p{N}\-]{1,36}(\/|\/[\p{L}\p{N}\-]{1,51}(\/|\/[\p{L}\p{N}\-]{1,101})?)?)?$/
the issue is that making the /
optional allows the regex to combine multiple of the [\p{L}\p{N}-] groups to match more then 36 or 51 chars and so forth. I made one assumption, that you can't have http://www.mydomain.p.ht//1234561-234561234561234-56123456123456şğ
, note the double /
For additional info, I highly reccommend http://www.regular-expressions.info/
Upvotes: 2