]> git.andy128k.dev Git - missing-tools.git/commitdiff
common regexps
authorAndrey Kutejko <andy128k@gmail.com>
Fri, 29 Nov 2013 23:32:02 +0000 (01:32 +0200)
committerAndrey Kutejko <andy128k@gmail.com>
Fri, 29 Nov 2013 23:32:02 +0000 (01:32 +0200)
src/regexp.php [new file with mode: 0644]

diff --git a/src/regexp.php b/src/regexp.php
new file mode 100644 (file)
index 0000000..7ccb64a
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+class Regexp
+{
+    public static function email()
+    {
+        $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
+        $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
+        $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
+        $quotedPair = '\\x5c[\\x00-\\x7f]';
+        $domainLiteral = "\\x5b($dtext|$quotedPair)*\\x5d";
+        $quotedString = "\\x22($qtext|$quotedPair)*\\x22";
+        $domain_ref = $atom;
+        $subDomain = "($domain_ref|$domainLiteral)";
+        $word = "($atom|$quotedString)";
+        $domain = "$subDomain(\\x2e$subDomain)+";
+        $localPart = "$word(\\x2e$word)*";
+        $addrSpec = "$localPart\\x40$domain";
+        return "!^$addrSpec$!D";
+    }
+
+    public static function url()
+    {
+        $ip = '(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}';
+        $dom = '([a-z0-9\.\-]+)';
+        return '!^(http|https|ftp|gopher)\://('.$ip.'|'.$dom.')!i';
+    }
+}
+