Regex
Aus SchnallIchNet
Inhaltsverzeichnis
IPv6 addresses
weil ipv6 mehrere verschiedene schreibweisen hat benoetigt man mehr als einen regulaeren ausdruck:
-
(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}
-
((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)
-
((?:[0-9A-Fa-f]{1,4}:){6,6})(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}
-
((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?) ::((?:[0-9A-Fa-f]{1,4}:)*)(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}
- regex 1 und 2 muessten auf alle ipv6 adressen matchen
- regex 3 und 4 muessten auf in ipv6 eingebettete ipv4 adressen matchen (z.b. ::ffff:192.168.1.2)
another single pattern (UNTESTED):
(?: # Mixed (?: # Non-compressed (?:[A-F0-9]{1,4}:){6} # Compressed with at most 6 colons |(?=(?:[A-F0-9]{0,4}:){0,6} (?:[0-9]{1,3}\.){3}[0-9]{1,3} # and 4 bytes (?![:.\w])) # and anchored # and at most 1 double colon (([0-9A-F]{1,4}:){0,5}|:)((:[0-9A-F]{1,4}){1,5}:|:) ) # 255.255.255. (?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3} # 255 (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) |# Standard (?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4} |# Compressed with at most 7 colons (?=(?:[A-F0-9]{0,4}:){0,7}[A-F0-9]{0,4} (?![:.\w])) # and anchored # and at most 1 double colon (([0-9A-F]{1,4}:){1,7}|:)((:[0-9A-F]{1,4}){1,7}|:) )(?![:.\w])
eMail addresses
\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b
URL matching
$regex = "((https?|ftp)\:\/\/)?"; // SCHEME //$regex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?"; // User and Pass $regex .= "([a-z0-9-.]*)\.([a-z]{2,3})"; // Host or IP $regex .= "(\:[0-9]{2,5})?"; // Port $regex .= "(\/([a-z0-9+\$_-]\.?)+)*\/?"; // Path $regex .= "(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?"; // GET Query $regex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?"; // Anchor