News for hackers. Stuff that matters.
Re:In search of the perfect URL validation regex (2010) by maciejgryka on Saturday September 25, 2021 @03:09PM (#28655444)
Using https://regex.help/, I got this beauty which passes all the ones, which should pass. Obviously some room for improvement ;) But it works!

  ^(?:http(?:(?:://(?:(?:(?:code\.google\.com/events/#&product=browser|\-\.~_!\$&'\(\)\*\+,;=:%40:80%2f::::::@ex\.com|foo\.(?:bar/\?q=Test%20URL\-encoded%20stuff|com/(?:\(something\)\?after=parens|unicode_\(\)_in_parens|b_(?:\(wiki\)(?:_blah)?#cite\-1|b(?:_\(wiki\)_\(again\)|/))))|uid(?::password@ex\.com(?::8080)?/|@ex\.com(?::8080)?/)|www\.ex\.com/wpstyle/\?p=364|223\.255\.255\.254|उदाहरण\.परीक्षा|1(?:42\.42\.1\.1/|337\.net)|مثال\.إختبار|df\.ws/123|a\.b\-c\.de|\.ws/䨹|⌘\.ws/|例子\.测试|j\.mp)|142\.42\.1\.1:8080/)|\.damowmow\.com/)|s://(?:www\.ex\.com/foo/\?bar=baz&inga=42&quux|foo_bar\.ex\.com/))|://(?:uid(?::password@ex\.com(?::8080)?|@ex\.com(?::8080)?)|foo\.com/b_b(?:_\(wiki\))?|⌘\.ws))|ftp://foo\.bar/baz)$
I had to replace some words with shorter ones to squeeze under 1000 char limit and there's no way to provide negative examples right now. Something to fix!
Re:In search of the perfect URL validation regex (2010) by axiosgunnar on Saturday September 25, 2021 @03:32PM (#28655622)
> ⌘\.ws

I guess this is the regex equivalent of overfitting :)

Re:In search of the perfect URL validation regex (2010) by saghm on Saturday September 25, 2021 @03:34PM (#28655636)
Yeah, not to mention "code.google.com" being right in there!
Re:In search of the perfect URL validation regex (2010) by maciejgryka on Saturday September 25, 2021 @03:40PM (#28655667)
Yeah, grex (the library powering this) is really cool, but doesn’t generalize very well. I’m sure there are ways to improve it, but it’s not a trivial thing to do.
Re:In search of the perfect URL validation regex (2010) by prox on Sunday September 26, 2021 @04:46AM (#28659366)
Any sufficiently advanced technology is indistinguishable from magic.

This kind of feels like a magic spell :)