Community Patterns

1

Capturing URL tester

Created·2016-06-07 08:21
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·2018-06-05 13:51
Flavor·PCRE (Legacy)

/
(?<ipv6_full>(?:^(?:f[c-f][0-9a-f]{2}|200[1-2]|0?100):).+|(?:.+:0{0,3}1$|(?:.+:ffff:(?:0:)?|^0{0,2}64:ff9b::)(?<ipv4_map>(?:25[0-5]|2[0-4]\d|[0-1]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d{1,2})){3})$))
/
gm
Open regex in editor

Description

Detects whether a given IPv6 string is within a reserved block, as defined on https://en.wikipedia.org/wiki/IPv6_address#Special_addresses

Please note that this assume that the string given is already a valid IPv6 address - If IPv6 validation is important to you, please make sure you pass any string through a more general IPv6 validator before testing it against this regex.

Also allows for extracting mapped IPv4 addresses from the IPv4 mapped address ranges.

Submitted by Rohaq