javascript - Why does regex take too long to evaluate for certain value? -
below regex :
(https?:\/\/)([a-za-z]{2,6}\.)*((?!.*[|!{}[\]^"*;]).)+(\.*)([a-za-z0-9\.\-\/\:\?&=_%#]+)+([&|?])+$ it validate url negative look-ahead allow characters other languages.
this happens when test @ http://regex101.com/#javascript:
for -
http://server.com/path?id=1111111 - no match
http://server.com/path?id=11111111 - timeout look took long evaluate.
http://server.com/path?id=111111111111111111111& - match
observations:
when value of query parameter increased above length times out.
but matching url length of parameter value doesn't matter.
why time out beyond length? part of regex need modify?
note: regex mandates url end ? or &
thanks in advance.
edit:
what need is, regex validate standard (for e.g. www.xyz.com or someip:port followed path parameters and/or query parameters, etc) urls. should back upwards characters other languages well. additional validation mandate url end ? or &.
the (…+)+ in ([a-za-z0-9\.\-\/\:\?&=_%#]+)+ leads catastrophic backtracking. removing 1 of pluses should help.
javascript regex regex-negation regex-lookarounds
No comments:
Post a Comment