Community Patterns

0

Capturing URL tester

Created·2018-10-26 07:02
Flavor·PCRE (Legacy)
This pcre style regex tests for valid URLs capturing the whole address. It will capture http and https only. Compatible with multiple sub-domains and raw IPV4 addresses, as well as paths, queries, and parameters. See below for examples: Will match these valid URLS: https://www.example.com/foo/?bar=baz&inga=42&quux http://foo.com/blah_(wikipedia)#cite-1 http://foo.com/blah_(wikipedia)_blah#cite-1 http://foo.com/unicode_(✪)_in_parens http://foo.com/(something)?after=parens http://code.google.com/events/#&product=browser http://142.42.1.1/ http://142.42.1.1:8080/ Will NOT match though valid URLS http://✪df.ws/123 http://userid:password@example.com:8080 http://userid:password@example.com:8080/ http://userid@example.com http://userid@example.com/ http://userid@example.com:8080 http://userid@example.com:8080/ http://userid:password@example.com http://userid:password@example.com/ Does NOT and should not match these bad URLS: http:// http://. http://.. http://../ http://? http://?? http://??/ http://# http://## http://##/ http://foo.bar?q=Spaces should be encoded // //a ///a /// http:///a foo.com rdar://1234 h://test http:// shouldfail.com :// should fail http://foo.bar/foo(bar)baz quux ftps://foo.bar/ http://-error-.invalid/ http://a.b--c.de/ http://-a.b.co http://a.b-.co http://3628126748 http://.www.foo.bar/ http://www.foo.bar./ http://.www.foo.bar./ Its not perfect, it will match http://999.999.999.999 and similar invalid IPV4 addresses and is not optimized but met my needs.
Submitted by 1nc3p710n

Community Library Entry

0

Regular Expression
Created·2020-06-03 13:13
Flavor·PCRE (Legacy)

/
^((?=[0-9.]+$)((25[0-5]|(2[0-4]|1[0-9])[0-9]|[1-9]?[0-9])\.){3}(25[0-5]|(2[0-4]|1[0-9])[0-9]|[1-9]?[0-9])|(?=[0-9.]*[a-zA-Z])([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])((\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]))*(\.[a-zA-Z]{2,31}))+)$
/
gm
Open regex in editor

Description

Accepts:

Valid IPv4:

127.0.0.1 192.168.1.1 192.168.1.255 192.168.255.255 0.0.0.0

Valid Hostnames:

abdc N7

Valid FQDN:

ABCD.fr truc-bidule.com sub.one-stuff.somewhere.com sub1.sub2.sub3.sub4.sub5.sub6.net

Rejects all the rest:

127.0.0.1 192.168.1.1a 192.068.1.255 30.168.1.255.1 127.1 192.168.1.256 -1.2.3.4 1.1.1.1. 3...3

523 rêve abc.f abc.c6 -n.fr abc.org a bc.fr ab. net to to to_to my_thing.com

Submitted by anonymous