- * wildcard in a search query should cause \w+ in highlighting, not \w* [Bug #10031]
[phpbb.git] / phpBB / develop / regex.php
blob4498204b4a83130fc84110988e2a616242cff004
1 <?php
2 //
3 // Security message:
4 //
5 // This script is potentially dangerous.
6 // Remove or comment the next line (die(".... ) to enable this script.
7 // Do NOT FORGET to either remove this script or disable it after you have used it.
8 //
9 die("Please read the first lines of this script for instructions on how to enable it");
12 // IP regular expressions
14 $dec_octet = '(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])';
15 $h16 = '[\dA-F]{1,4}';
16 $ipv4 = "(?:$dec_octet\.){3}$dec_octet";
17 $ls32 = "(?:$h16:$h16|$ipv4)";
19 $ipv6_construct = array(
20 array(false, '', '{6}', $ls32),
21 array(false, '::', '{5}', $ls32),
22 array('', ':', '{4}', $ls32),
23 array('{1,2}', ':', '{3}', $ls32),
24 array('{1,3}', ':', '{2}', $ls32),
25 array('{1,4}', ':', '', $ls32),
26 array('{1,5}', ':', false, $ls32),
27 array('{1,6}', ':', false, $h16),
28 array('{1,7}', ':', false, '')
31 $ipv6 = '(?:';
32 foreach ($ipv6_construct as $ip_type)
34 $ipv6 .= '(?:';
35 if ($ip_type[0] !== false)
37 $ipv6 .= "(?:$h16:)" . $ip_type[0];
39 $ipv6 .= $ip_type[1];
40 if ($ip_type[2] !== false)
42 $ipv6 .= "(?:$h16:)" . $ip_type[2];
44 $ipv6 .= $ip_type[3] . ')|';
46 $ipv6 = substr($ipv6, 0, -1) . ')';
48 echo 'IPv4: ' . $ipv4 . "<br />\nIPv6: " . $ipv6 . "<br />\n";
50 // URL regular expressions
52 $pct_encoded = "%[\dA-F]{2}";
53 $unreserved = 'a-z0-9\-._~';
54 $sub_delims = '!$&\'()*+,;=';
55 $pchar = "(?:[$unreserved$sub_delims:@|]+|$pct_encoded)"; // rfc: no "|"
57 $scheme = '[a-z][a-z\d+\-.]*';
58 $reg_name = "(?:[$unreserved$sub_delims:@|]+|$pct_encoded)+"; // rfc: * instead of + and no "|" and no "@" and no ":" (included instead of userinfo)
59 //$userinfo = "(?:(?:[$unreserved$sub_delims:]+|$pct_encoded))*";
60 $ipv4_simple = '[0-9.]+';
61 $ipv6_simple = '\[[a-z0-9.]+:[a-z0-9.]+:[a-z0-9.:]+\]';
62 $host = "(?:$reg_name|$ipv4_simple|$ipv6_simple)";
63 $port = '\d*';
64 //$authority = "(?:$userinfo@)?$host(?::$port)?";
65 $authority = "$host(?::$port)?";
66 $segment = "$pchar*";
67 $path_abempty = "(?:/$segment)*";
68 $hier_part = "/{2}$authority$path_abempty";
69 $query = "(?:[$unreserved$sub_delims:@/?|]+|$pct_encoded)*"; // pchar | "/" | "?", rfc: no "|"
70 $fragment = $query;
72 $url = "$scheme:$hier_part(?:\?$query)?(?:\#$fragment)?";
73 echo 'URL: ' . $url . "<br />\n";
75 // no scheme, shortened authority, but host has to start with www.
76 $www_url = "www\.$reg_name(?::$port)?$path_abempty(?:\?$query)?(?:\#$fragment)?";
77 echo 'www.URL: ' . $www_url . "<br />\n";
79 // no schema and no authority
80 $relative_url = "$segment$path_abempty(?:\?$query)?(?:\#$fragment)?";
81 echo 'relative URL: ' . $relative_url . "<br />\n";