News for hackers. Stuff that matters.
Re:In search of the perfect URL validation regex (2010) by elif on Saturday September 25, 2021 @02:01PM (#28654949)
how would you even "parse" a url with a regex? dynamically defined named subpatterns for each url parameter? I think the best i could do on paper with a regex is say "yup this is a url" or maybe "yup i can count the number of params"

Unless it was a specific url with specific params?

Re:In search of the perfect URL validation regex (2010) by chrismorgan on Saturday September 25, 2021 @02:21PM (#28655081)
Match groups so you can split it up into scheme, username, password, host, port, path, query, fragment. Not difficult to approximate, though for best results with diverse schemes you’d want an engine that allows repeated named groups, and I don’t know if any do (JavaScript and Python don’t).
Re:In search of the perfect URL validation regex (2010) by powersnail on Saturday September 25, 2021 @02:34PM (#28655170)
Python's `regex` package does allow repeated named group.
Re:In search of the perfect URL validation regex (2010) by elif on Sunday September 26, 2021 @02:31PM (#28663313)
I mean ya that would match a query string, but it wouldn't parse it?
Re:In search of the perfect URL validation regex (2010) by tyingq on Saturday September 25, 2021 @03:05PM (#28655402)
I assume they meant "some regex implementation, including replace and/or match groups".

Like, for just the params part (yes, broken and simplistic):

  #!/usr/bin/perl
  $_="a=b&c=d&e=f&whatever=some thing";
  while (s/^([^&]*)=([^&]*)(&|$)//) {
    print "[$1] [$2]\n";
  }