/ \ { } p ! ; : ; |...

Keyboard Shortcuts?
Next menu item
Previous menu item
Previous man page
Next man page
Scroll to bottom
Scroll to top
Goto homepage
Goto search(current page)
Focus search box
Change language:
Brazilian Portuguese
Chinese (Simplified)
preg_match
preg_match & 执行一个正则表达式匹配
int preg_match
( string $pattern
, string $subject
[, array &$matches
[, int $flags = 0
[, int $offset = 0
要搜索的模式,字符串类型。
输入字符串。
如果提供了参数matches,它将被填充为搜索结果。
$matches[0]将包含完整模式匹配到的文本, $matches[1]
将包含第一个捕获子组匹配到的文本,以此类推。
flags可以被设置为以下标记值:
PREG_OFFSET_CAPTURE
如果传递了这个标记,对于每一个出现的匹配返回时会附加字符串偏移量(相对于目标字符串的)。
注意:这会改变填充到matches参数的数组,使其每个元素成为一个由
第0个元素是匹配到的字符串,第1个元素是该匹配字符串
在目标字符串subject中的偏移量。
通常,搜索从目标字符串的开始位置开始。可选参数 offset 用于
指定从目标字符串的某个未知开始搜索(单位是字节)。
使用offset参数不同于向preg_match()
传递按照位置通过substr($subject, $offset)截取目标字符串结果,
因为pattern可以包含断言比如^, $
或者(?&=x)。 比较:
以上例程会输出:
当这个示例使用截取后传递时
&?php$subject&=&"abcdef";$pattern&=&'/^def/';preg_match($pattern,&substr($subject,3),&$matches,&PREG_OFFSET_CAPTURE);print_r($matches);?&
将会产生匹配
[0] =& Array
[0] =& def
preg_match()返回 pattern 的匹配次数。
它的值将是0次(不匹配)或1次,因为preg_match()在第一次匹配后
将会停止搜索。不同于此,它会一直搜索subject
直到到达结尾。
如果发生错误preg_match()返回 FALSE。
Example #1 查找文本字符串&php&
&?php//模式分隔符后的"i"标记这是一个大小写不敏感的搜索if&(preg_match("/php/i",&"PHP&is&the&web&scripting&language&of&choice."))&{&&&&echo&"A&match&was&found.";}&else&{&&&&echo&"A&match&was&not&found.";}?&
Example #2 查找单词&word&
&?php/*&模式中的\b标记一个单词边界,所以只有独立的单词"web"会被匹配,而不会匹配&*&单词的部分内容比如"webbing"&或&"cobweb"&*/if&(preg_match("/\bweb\b/i",&"PHP&is&the&web&scripting&language&of&choice."))&{&&&&echo&"A&match&was&found.";}&else&{&&&&echo&"A&match&was&not&found.";}if&(preg_match("/\bweb\b/i",&"PHP&is&the&website&scripting&language&of&choice."))&{&&&&echo&"A&match&was&found.";}&else&{&&&&echo&"A&match&was&not&found.";}?&
Example #3 获取URL中的域名
&?php//从URL中获取主机名称preg_match('@^(?:http://)?([^/]+)@i',&&&&"http://www.php.net/index.html",&$matches);$host&=&$matches[1];//获取主机名称的后面两部分preg_match('/[^.]+\.[^.]+$/',&$host,&$matches);echo&"domain&name&is:&{$matches[0]}\n";?&
以上例程会输出:
domain name is: php.net
Example #4 使用命名子组
&?php$str&=&'foobar:&2008';preg_match('/(?P&name&\w+):&(?P&digit&\d+)/',&$str,&$matches);/*&下面例子在php&5.2.2(pcre&7.0)或更新版本下工作,&然而,&为了后向兼容,&上面的方式是推荐写法.&*///&preg_match('/(?&name&\w+):&(?&digit&\d+)/',&$str,&$matches);print_r($matches);?&
以上例程会输出:
[0] =& foobar: 2008
[name] =& foobar
[1] =& foobar
[digit] =& 2008
[2] =& 2008
如果你仅仅想要检查一个字符串是否包含另外一个字符串,不要使用preg_match()。
使用或替代完成工作会更快。
- 执行一个全局正则表达式匹配
- 执行一个正则表达式的搜索和替换
- 通过一个正则表达式分隔字符串
- 返回最后一个PCRE正则执行产生的错误代码
Simple regexRegex quick reference[abc]& && A single character: a, b or c[^abc]& && Any single character but a, b, or c[a-z]& && Any single character in the range a-z[a-zA-Z]& && Any single character in the range a-z or A-Z^& && Start of line$& && End of line\A& && Start of string\z& && End of string.& && Any single character\s& && Any whitespace character\S& && Any non-whitespace character\d& && Any digit\D& && Any non-digit\w& && Any word character (letter, number, underscore)\W& && Any non-word character\b& && Any word boundary character(...)& && Capture everything enclosed(a|b)& && a or ba?& && Zero or one of aa*& && Zero or more of aa+& && One or more of aa{3}& && Exactly 3 of aa{3,}& && 3 or more of aa{3,6}& && Between 3 and 6 of aoptions: i case insensitive m make dot match newlines x ignore whitespace in regex o perform #{...} substitutions only once
Sometimes its useful to negate a string. The first method which comes to mind to do this is: [^(string)] but this of course won't work. There is a solution, but it is not very well known. This is the simple piece of code on how a negation of a string is done:(?:(?!string).)?: makes a subpattern (see ) and ?! is a negative look ahead. You put the negative look ahead in front of the dot because you want the regex engine to first check if there is an occurrence of the string you are negating. Only if it is not there, you want to match an arbitrary character.Hope this helps some ppl.
here is a small tool for someone learning to use regular expressions. it's very basic, and allows you to try different patterns and combinations. I made it to help me, because I like to try different things, to get a good understanding of how things work.&?php$search = isset($_POST['search'])?$_POST['search']:"//";$match = isset($_POST['match'])?$_POST['match']:"&&";echo '&form method="post"&';echo 's: &input style="width:400" name="search" type="text" value="'.$search.'" /&&br /&';echo 'm:&input style="width:400" name="match" type="text" value="'.$match.'" /&&input type="submit" value="go" /&&/form&&br /&';if (preg_match($search, $match)){echo "matches";}else{echo "no match";}?&
For those who search for a unicode regular expression example using preg_match here it is:Check for Persian digitspreg_match( "/[^\x{06F0}-\x{06F9}\x]+/u" , '??????????' );
I see a lot of people trying to put together phone regex's and struggling (hey, no worries...they're complicated). Here's one that we use that's pretty nifty. It's not perfect, but it should work for most non-idealists.
*** Note: Only matches U.S. phone numbers. ***
$regex = '/^(?:1(?:[. -])?)?(?:\((?=\d{3}\)))?([2-9]\d{2})(?:(?&=\(\d{3})\))? ?(?:(?&=\d{3})[.-])?([2-9]\d{2})[. -]?(\d{4})(?: (?i:ext)\.? ?(\d{1,5}))?$/';
$regex = '/^(?:1(?:[. -])?)?(?:\((?=\d{3}\)))?([2-9]\d{2})'
& & & & .'(?:(?&=\(\d{3})\))? ?(?:(?&=\d{3})[.-])?([2-9]\d{2})'
& & & & .'[. -]?(\d{4})(?: (?i:ext)\.? ?(\d{1,5}))?$/';
If you're wondering why all the non-capturing subpatterns (which look like this "(?:", it's so that we can do this:
$formatted = preg_replace($regex, '($1) $2-$3 ext. $4', $phoneNumber);
$formatted = "($matches[1]) $matches[2]-$matches[3]";
if ($matches[4]) $formatted .= " $matches[4]";
*** Results: ***
520-555-5542 :: MATCH
520.555.5542 :: MATCH
:: MATCH
520 555 5542 :: MATCH
520) 555-5542 :: FAIL
(520 555-5542 :: FAIL
(520)555-5542 :: MATCH
(520) 555-5542 :: MATCH
(520) 555 5542 :: MATCH
520-555.5542 :: MATCH
520 555-0555 :: MATCH
(520)5555542 :: MATCH
520.555-4523 :: MATCH
:: MATCH
514 555 1231 :: MATCH
1 555 555 5555 :: MATCH
1.555.555.5555 :: MATCH
1-555-555-5555 :: MATCH
520-555-5542 ext.123 :: MATCH
520.555.5542 EXT 123 :: MATCH
Ext. 7712 :: MATCH
520 555 5542 ext 5 :: MATCH
520) 555-5542 :: FAIL
(520 555-5542 :: FAIL
(520)555-5542 ext .4 :: FAIL
(512) 555-1234 ext. 123 :: MATCH
1(555)555-5555 :: MATCH
Because making a truly correct email validation function is harder than one may think, consider using this one which comes with PHP through the filter_var function ():&?php$email = "someone@domain .local";if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {& & echo "E-mail is not valid";} else {& & echo "E-mail is valid";}?&
If you want to validate an email in one line, use filter_var() function !easy use, as described in the document example :var_dump(filter_var('', FILTER_VALIDATE_EMAIL));
If you need to check whether string is a serialized representation of variable(sic!) you can use this :&?php$string = "a:0:{}";if(preg_match("/(a|O|s|b)\x3a[0-9]*?((\x3a((\x7b?(.+)\x7d)|(\x22(.+)\x22\x3b)))|(\x3b))/", $string)) {echo "Serialized.";}else {echo "Not serialized.";}?&But don't forget, string in serialized representation could be VERY big, so match work can be slow, even with fast preg_* functions.
I just learned about named groups from a Python friend today and was curious if PHP supported them, guess what -- it does!!!&?php&& preg_match("/(?P&foo&abc)(.*)(?P&bar&xyz)/",& & & & & & & & & & && 'abcdefghijklmnopqrstuvwxyz',& & & & & & & & & & && $matches);&& print_r($matches);?&will produce: Array(& & [0] =& abcdefghijklmnopqrstuvwxyz& & [foo] =& abc& & [1] =& abc& & [2] =& defghijklmnopqrstuvw& & [bar] =& xyz& & [3] =& xyz)Note that you actually get the named group as well as the numerical keyvalue too, so if you do use them, and you're counting array elements, beaware that your array might be bigger than you initially expect it to be.
If you need to match specific wildcards in IP address, you can use this regexp:&?php$ip = '10.1.66.22';$cmp = '10.1.??.*';$cnt = preg_match('/^'& && .str_replace(& && array('\*','\?'),& && array('(.*?)','[0-9]'),& && preg_quote($cmp)).'$/',& && $ip);echo $cnt;?&where '?' is exactly one digit and '*' is any number of any characters. $cmp mask can be provided wild by user, $cnt equals (int) 1 on match or 0.
I noticed that in order to deal with UTF-8 texts, without having to recompile php with the PCRE UTF-8 flag enabled, you can just add the following sequence at the start of your pattern: (*UTF8)for instance : '#(*UTF8)[[:alnum:]]#' will return TRUE for 'é' where '#[[:alnum:]]#' will return FALSEfound this very very useful tip after hours of research over the web directly in pcre website right here : there are many further informations about UTF-8 support in the libhop that will help!--cedric
Example of validating an email address and breaking it into 3 parts ( local, domain name, domain suffix )A case insensitive& email is valid if:1) local matches letters a..z or characters . - _ + 2) domain name matches letters a..z or characters - _3) domain suffix matches letters a..z and is between 2 and 4 characters in length &?phppreg_match('/(^[a-zA-Z_.+-]+)@([a-zA-Z_-]+).([a-zA-Z]{2,4}$)/i', "", $matches);var_export($matches);?&outputs:Array(& & [0] =& & & [1] =& jeff& & [2] =& nowhere& & [3] =& com)
I have been working on a email system that will automatically generate a text email from a given HTML email by using strip_tags(). The only issue I ran into, for my needs, were that the anchors would not keep their links. I search for a little while and could not find anything to strip the links from the tags so I generated my own little snippet. I am posting it here in hopes that others may find it useful and for later reference.A note to keep in mind:I was primarily concerned with valid HTML so if attributes do no use ' or " to contain the values then this will need to be tweaked.If you can edit this to work better, please let me know.&?phpfunction replaceAnchorsWithText($data) {& & $regex& = '/(&a\s*'; $regex .= '(.*?)\s*'; $regex .= 'href=[\'"]+?\s*(?P&link&\S+)\s*[\'"]+?'; $regex .= '\s*(.*?)\s*&\s*'; $regex .= '(?P&name&\S+)'; $regex .= '\s*&\/a&)/i'; if (is_array($data)) {& & & & $data = "{$data['name']}({$data['link']})";& & }& & return preg_replace_callback($regex, 'replaceAnchorsWithText', $data);}$input& = 'Test 1: &a href="http: //php.net1"&PHP.NET1&/a&.&br /&';$input .= 'Test 2: &A name="test" HREF=\'HTTP: //PHP.NET2\' target="_blank"&PHP.NET2&/A&.&BR /&';$input .= 'Test 3: &a hRef=http: //php.net3&php.net3&/a&&br /&';$input .= 'This last line had nothing to do with any of this';echo replaceAnchorsWithText($input).'&hr/&';?&Will output:Test 1: PHP.NET1(http: //php.net1).Test 2: PHP.NET2(HTTP: //PHP.NET2).Test 3: php.net3 (is still an anchor)This last line had nothing to do with any of thisPosting to this site is painful...Had to break up the regex and had to break the test links since it was being flagged as spam...
Bugs of preg_match (PHP-version 5.2.5)In most cases, the following example will show one of two PHP-bugs discovered with preg_match depending on your PHP-version and configuration.&?php$text = "test=";for ($i = 0; $i++ & 100000;)& & $text .= "%AB";$pattern& & = '/^(?:[;\/?:@&=+$,]|(?:[^\W_]|[-_.!~*\()\[\] ])|(?:%[\da-fA-F]{2}))*$/';& & var_dump( preg_match( $pattern, $text ) );?&Possible bug (1):=============On one of our Linux-Servers the above example crashes PHP-execution with a C(?) Segmentation Fault(!). This seems to be a known bug (see ), but I don't know if it has been fixed, yet.If you are looking for a work-around, the following code-snippet is what I found helpful. It wraps the possibly crashing preg_match call by decreasing the PCRE recursion limit in order to result in a Reg-Exp error instead of a PHP-crash.&?php[...]$former_recursion_limit = ini_set( "pcre.recursion_limit", 10000 );$result = preg_match( $pattern, $text );ini_set( "pcre.recursion_limit", $former_recursion_limit );if ( PREG_RECURSION_LIMIT_ERROR === preg_last_error() ){& & $result = [...];& & & & [...]} ?&Possible bug (2):=============On one of our Windows-Servers the above example does not crash PHP, but (directly) hits the recursion-limit. Here, the problem is that preg_match does not return boolean(false) as expected by the description / manual of above.In short, preg_match seems to return an int(0) instead of the expected boolean(false) if the regular expression could not be executed due to the PCRE recursion-limit. So, if preg_match results in int(0) you seem to have to check preg_last_error() if maybe an error occurred.
for those coming over from ereg, preg_match can be quite intimidating. to get started here is a migration tip.
&?php
if(ereg('[^0-9A-Za-z]',$test_string)) if(preg_match('/[^0-9A-Za-z]/',$test_string)) ?&
This sample is for checking persian character:&?php&& preg_match("/[\x{0600}-\x{06FF}\x]{1,32}/u", '????');?&
There does not seem to be any mention of the PHP version of switches that can be used with regular expressions.
preg_match_all('/regular expr/sim',$text).
The s i m being the location for and available switches (I know about)
The i is to ignore letter cases (this is commonly known - I think)
The s tells the code NOT TO stop searching when it encounters \n (line break) - this is important with multi-line entries for example text from an editor that needs search.
The m tells the code it is a multi-line entry, but importantly allows the use of ^ and $ to work when showing start and end.
I am hoping this will save someone from the 4 hours of torture that I endured, trying to workout this issue.
Just an interesting note. Was just updating code to replace ereg() with strpos() and preg_match and the thought occured that preg_match() could be optimized to quit early when only searching if a string begins with something, for example&?phpif(preg_match("/^http/", $url)){ }?& vs &?php if(strpos($url, "http") === 0){}?&As I guessed, strpos() is always faster (about 2x) for short strings like a URL but for very long strings of several paragraphs (e.g. a block of XML) when the string doesn't start with the needle preg_match as twice as fast as strpos() as it doesn't scan the entire string.So, if you are searching long strings and expect it to normally be true (e.g. validating XML), strpos() is a much faster BUT if you expect if to often fail, preg_match is the better choice.
Workaround for getting the offset in UTF-8
(in some cases mb_strpos might be an option as well)
&?php
if(preg_match($pattern,$haystack,$out,PREG_OFFSET_CAPTURE)) {
& & $offset = strlen(utf8_decode(substr($haystack,0,$out[0][1])));
}
?&
This sample regexp may be useful if you are working with DB field types. (?P&type&\w+)($|\((?P&length&(\d+|(.*)))\))For example, if you are have a such type as "varchar(255)" or "text", the next fragment&?php&& $type = 'varchar(255)';& preg_match('/(?P&type&\w+)($|\((?P&length&(\d+|(.*)))\))/', $type, $field);&& print_r($field);?&will output something like this:Array ( [0] =& varchar(255) [type] =& varchar [1] =& varchar [2] =& (255) [length] =& 255 [3] =& 255 [4] =& 255 )
This is a function that uses regular expressions to match against the various VAT formats required across the EU.
&?php
function checkVatNumber( $country, $vat_number ) {
& & switch($country) {
& & & & case 'Austria':
& & & & & & $regex = '/^(AT){0,1}U[0-9]{8}$/i';
& & & & & &
& & & & case 'Belgium':
& & & & & & $regex = '/^(BE){0,1}[0]{0,1}[0-9]{9}$/i';
& & & & & &
& & & & case 'Bulgaria':
& & & & & & $regex = '/^(BG){0,1}[0-9]{9,10}$/i';
& & & & & &
& & & & case 'Cyprus':
& & & & & & $regex = '/^(CY){0,1}[0-9]{8}[A-Z]$/i';
& & & & & &
& & & & case 'Czech Republic':
& & & & & & $regex = '/^(CZ){0,1}[0-9]{8,10}$/i';
& & & & & &
& & & & case 'Denmark':
& & & & & & $regex = '/^(DK){0,1}([0-9]{2}[\ ]{0,1}){3}[0-9]{2}$/i';
& & & & & &
& & & & case 'Estonia':
& & & & case 'Germany':
& & & & case 'Greece':
& & & & case 'Portugal':
& & & & & & $regex = '/^(EE|EL|DE|PT){0,1}[0-9]{9}$/i';
& & & & & &
& & & & case 'France':
& & & & & & $regex = '/^(FR){0,1}[0-9A-Z]{2}[\ ]{0,1}[0-9]{9}$/i';
& & & & & &
& & & & case 'Finland':
& & & & case 'Hungary':
& & & & case 'Luxembourg':
& & & & case 'Malta':
& & & & case 'Slovenia':
& & & & & & $regex = '/^(FI|HU|LU|MT|SI){0,1}[0-9]{8}$/i';
& & & & & &
& & & & case 'Ireland':
& & & & & & $regex = '/^(IE){0,1}[0-9][0-9A-Z\+\*][0-9]{5}[A-Z]$/i';
& & & & & &
& & & & case 'Italy':
& & & & case 'Latvia':
& & & & & & $regex = '/^(IT|LV){0,1}[0-9]{11}$/i';
& & & & & &
& & & & case 'Lithuania':
& & & & & & $regex = '/^(LT){0,1}([0-9]{9}|[0-9]{12})$/i';
& & & & & &
& & & & case 'Netherlands':
& & & & & & $regex = '/^(NL){0,1}[0-9]{9}B[0-9]{2}$/i';
& & & & & &
& & & & case 'Poland':
& & & & case 'Slovakia':
& & & & & & $regex = '/^(PL|SK){0,1}[0-9]{10}$/i';
& & & & & &
& & & & case 'Romania':
& & & & & & $regex = '/^(RO){0,1}[0-9]{2,10}$/i';
& & & & & &
& & & & case 'Sweden':
& & & & & & $regex = '/^(SE){0,1}[0-9]{12}$/i';
& & & & & &
& & & & case 'Spain':
& & & & & & $regex = '/^(ES){0,1}([0-9A-Z][0-9]{7}[A-Z])|([A-Z][0-9]{7}[0-9A-Z])$/i';
& & & & & &
& & & & case 'United Kingdom':
& & & & & & $regex = '/^(GB){0,1}([1-9][0-9]{2}[\ ]{0,1}[0-9]{4}[\ ]{0,1}[0-9]{2})|([1-9][0-9]{2}[\ ]{0,1}[0-9]{4}[\ ]{0,1}[0-9]{2}[\ ]{0,1}[0-9]{3})|((GD|HA)[0-9]{3})$/i';
& & & & & &
& & & & default:
& & & & & & return -1;
& & & & & &
& & }
& &
& & return preg_match($regex, $vat_number);
}
?&
To extract scheme, host, path, ect. simply use
& $url& = '';
& $url .= ':10000';
& $url .= '/path/to/file.php?a=1&b=2#anchor';
& $url_data = parse_url ( $url );
& print_r ( $url_data );
?&
___
prints out something like:
Array
(
& & [scheme] =& http
& & [host] =& wild.subdomain.orgy.domain.co.uk
& & [port] =& 10000
& & [user] =& name
& & [pass] =& pass
& & [path] =& /path/to/file.php
& & [query] =& a=1&b=2
& & [fragment] =& anchor
)
In my tests parse_url is up to 15x faster than preg_match(_all)!
Some times a Hacker use a php file or shell as a image to hack your website. so if you try to use move_uploaded_file() function as in example to allow for users to upload files, you must check if this file contains a bad codes or not so we use this function. preg matchin this function we useunlink() - after you upload file check a file with below function. &?phpfunction is_clean_file ($file){& & if (file_exists($file))& & {& & & & $contents = file_get_contents($file);& & }& & else& & {& & & & exit($file." Not exists.");& & }& & if (preg_match('/(base64_|eval|system|shell_|exec|php_)/i',$contents))& & {& & & & return true;& & }& & else if (preg_match("#&\#x([0-9a-f]+);#i", $contents))& & {& & & & return true;& & }& & elseif (preg_match('#&\#([0-9]+);#i', $contents))& & {& & & & return true;& & }& & elseif (preg_match("#([a-z]*)=([\`\'\"]*)script:#iU", $contents))& & {& & & & return true;& & }& & elseif (preg_match("#([a-z]*)=([\`\'\"]*)javascript:#iU", $contents))& & {& & & & return true;& & }& & elseif (preg_match("#([a-z]*)=([\'\"]*)vbscript:#iU", $contents))& & {& & & & return true;& & }& & elseif (preg_match("#(&[^&]+)style=([\`\'\"]*).*expression\([^&]*&#iU", $contents))& & {& & & & return true;& & }& & elseif (preg_match("#(&[^&]+)style=([\`\'\"]*).*behaviour\([^&]*&#iU", $contents))& & {& & & & return true;& & }& & elseif (preg_match("#&/*(applet|link|style|script|iframe|frame|frameset|html|body|title|div|p|form)[^&]*&#i", $contents))& & {& & & & return true;& & }& & else& & {& & & & return false;& & }}?&Use&?php$image&& = "simpleimage.png";if (is_clean_file($image)){& & echo "Bad codes this is not image";& & unlink($image);}else{& & echo "This is a real image.";}?&
I recently encountered a problem trying to capture multiple instances of named subpatterns from filenames.Therefore, I came up with this function.The function allows you to pass through flags (in this version it applies to all expressions tested), and generates an array of search results.Enjoy!&?phpfunction preg_match_multiple( & array $patterns=array(), & $subject=null,& &$findings=array(),& $flags=false,& &$errors=array()) {& foreach( $patterns as $name =& $pattern )& {& & if( 1 &= preg_match_all( $pattern, $subject, $found, $flags ) )& & {& & & $findings[$name] = $found;& & } else & & {& & & if( PREG_NO_ERROR !== ( $code = preg_last_error() ))& & & {& & & & $errors[$name] = $code;& & & } else $findings[$name] = array();& & }& }& return (0===sizeof($errors));}?&
Be aware of bug https://bugs.php.net/bug.php?id=50887 when using sub patterns: Un-matched optional sub patterns at the end won't show up in $matches.Here is a workaround: Assign a name to all subpatterns you are interested in, and merge $match afterwards with an constant array containing some reasonable default values:&?phpif (preg_match('/^(?P&lang&[^;*][^;]*){1}(?:;q=(?P&qval&[0-9.]+))?$/u', 'de', $match)){& $match = array_merge(array('lang' =& '', 'qval' =& ''), $match);& print_r($match);}?&This outputs:Array(& & [lang] =& de& & [qval] =& & & [0] =& de& & [1] =& de)Instead of:Array(& & [0] =& de& & [lang] =& de& & [1] =& de)
Basic test for invalid UTF-8 that can hi-jack IE:&?php$valid = (preg_match('/^./us', $text) == 1);?&See
for details.---Test for valid UTF-8 and XML/XHTML character range compatibility:&?php$invalid = preg_match('@[^\x9\xA\xD\x20-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]@u', $text)?&Ref:
Testing the speed of preg_match against stripos doing insensitive case search in strings:&?php$string = "Hey, how are you? I'm a string.";$start = microtime(true);for ($i = 1; $i & ; $i++) {& & $bool = preg_match('/you/i', $string);}$end = microtime(true);$pcre_lasted = $end - $start; $start = microtime(true);for ($i = 1; $i & ; $i++) {& & $bool = stripos($string, 'you') !== false;}$end = microtime(true);$stripos_lasted = $end - $start; echo "Preg_match lasted: {$pcre_lasted}&br /&Stripos lasted: {$stripos_lasted}";?&So unless you really need to test a string against a regular expression, always use strpos / stripos and other string functions to find characters and strings within other strings.
As I wasted lots of time finding a REAL regex for URLs and resulted in building it on my own, I now have found one, that seems to work for all kinds of urls:
&?php
& & $regex = "((https?|ftp)\:\/\/)?"; $regex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?"; $regex .= "([a-z0-9-.]*)\.([a-z]{2,3})"; $regex .= "(\:[0-9]{2,5})?"; $regex .= "(\/([a-z0-9+\$_-]\.?)+)*\/?"; $regex .= "(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?"; $regex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?"; ?&
Then, the correct way to check against the regex ist as follows:
&?php
& & && if(preg_match("/^$regex$/", $url))
& & && {
& & & & & & && return true;
& & && }
?&
If your regular expression does not match with long input text when you think it should, you might have hit the PCRE backtrack default limit of 100000. See
I spent a while replacing all my ereg() calls to preg_match(), since ereg() is now deprecated and will not be supported as of v 6.0.
Just a warning regarding the conversion, the two functions behave very similarly, but not exactly alike. Obviously, you will need to delimit your pattern with '/' or '|' characters.
The difference that stumped me was that preg_replace overwrites the $matches array regardless if a match was found. If no match was found, $matches is simply empty.
ereg(), however, would leave $matches alone if a match was not found. In my code, I had repeated calls to ereg, and was populating $matches with each match. I was only interested in the last match. However, with preg_match, if the very last call to the function did not result in a match, the $matches array would be overwritten with a blank value.
Here is an example code snippet to illustrate:
&?php
$test = array('yes','no','yes','no','yes','no');
foreach ($test as $key=&$value) {
& ereg("yes",$value,$matches1);
& preg_match("|yes|",$value,$matches2);
}
& print "ereg result: $matches1[0]&br&";
& print "preg_match result: $matches2[0]&br&";
?&
The output is:
ereg result: yes
preg_match result:
($matches2[0] in this case is empty)
I believe the preg_match behavior is cleaner. I just thought I would report this to hopefully save others some time.
I found this rather useful for testing mutliple strings when developing a regex pattern.&?php function preg_match_batch( $expr, $batch=array() ){$returnMe = array();foreach( $batch as $str )& & {preg_match($expr, $str, $found);$returnMe[$str] = $found;& & }& & return $returnMe;}?&
Here is a function that decreases the numbers inside a string (useful to convert DOM object into simplexml object)e.g.: decremente_chaine("somenode-&anode[2]-&achildnode[3]") will return "somenode-&anode[1]-&achildnode[2]"the numbering of the nodes in simplexml starts from zero, but from 1 in DOM xpath objects&?phpfunction decremente_chaine($chaine)& & {& & & & preg_match_all("/[0-9]+/",$chaine,$out,PREG_OFFSET_CAPTURE);& & & & & & for($i=0;$i&sizeof($out[0]);$i++)& & & & & & {& & & & & & & & $longueurnombre = strlen((string)$out[0][$i][0]);& & & & & & & & $taillechaine = strlen($chaine);& & & & & & & & $debut = substr($chaine,0,$out[0][$i][1]);& & & & & & & & $milieu = ($out[0][$i][0])-1;& & & & & & & & $fin = substr($chaine,$out[0][$i][1]+$longueurnombre,$taillechaine);& & & & & & & && if(preg_match('#[1][0]+$#', $out[0][$i][0]))& & & & & & & && {& & & & & & & & & & for($j = $i+1;$j&sizeof($out[0]);$j++)& & & & & & & & & & {& & & & & & & & & & & & $out[0][$j][1] = $out[0][$j][1] -1;& & & & & & & & & & }& & & & & & & && }& & & & & & & & $chaine = $debut.$milieu.$fin;& & & & & & }& & & & return $chaine;& & }?&
Was working on a site that needed japanese and alphabetic letters and needed to validate input using preg_match, I tried using \p{script} but didn't work:&?php$pattern ='/^([-a-zA-Z0-9_\p{Katakana}\p{Hiragana}\p{Han}]*)$/u'; ?&So I tried with ranges and it worked:&?php$pattern ='/^[-a-zA-Z0-9_\x{30A0}-\x{30FF}'& & & && .'\x{3040}-\x{309F}\x{4E00}-\x{9FBF}\s]*$/u';$match_string = '印刷最安 ニキビ跡除去 ゲームボーイ';if (preg_match($pattern, $match_string)) {& & echo "Found - pattern $pattern";} else {& & echo "Not found - pattern $pattern";}?&U+4E00–U+9FBF KanjiU+3040–U+309F HiraganaU+30A0–U+30FF KatakanaHope its useful, it took me several hours to figure it out.
Matching a backslash character can be confusing, because double escaping is needed in the pattern: first for PHP, second for the regex engine&?phppreg_match('/\n/','\n');&& preg_match('/\\\n/','\n'); $subject = file_get_contents('myfile.txt');preg_match('/\\\'/',$subject);& & preg_match('/\\\\\'/',$subject);& preg_match('/\\\\\\\/',$subject); preg_match('/\\\\n/','\\n');preg_match('/\\\n/','\\n'); ?&
When you use preg_match() for security purpose or huge data processing,mayby you should make consideration for backtrack_limit and recursion_limit.These limits may bring wrong matching result.You can verify whether you hit these limits by checking preg_last_error().
When using a 'bad words reject string' filter, preg_match is MUCH faster than strpos / stripos. Because in the other cases, you would need to do a foreach for each word. With efficient programming, the foreach is ONLY faster when the first word in the ban-list is found.(for 12 words, 100,000 iterations, no word found)stripos - Taken 1.4876 seconds.strpos - Taken 1.4207 seconds.preg_match - Taken 0.189 seconds.Interesting fact:With long words ('averylongwordtospitepreg'), the difference is only much less. Only about a 2/3rd of the time instead of 1/6th&?php$words = array('word1', 'word2', 'word3', 'word4', 'word5', 'word6', 'word7', 'word8', 'word9', 'word10', 'word11', 'word12' );$teststring = 'ThIs Is A tEsTsTrInG fOr TeStInG.';$count = 100000;$find = 0;$start = microtime(TRUE);for ($i = 0; $i & $count; $i++) {& & foreach ($words as $word) {& & & & if (stripos($teststring, $word) !== FALSE) {& & & & & & $find++;& & & & & && & & & }& & }}echo 'stripos - Taken ' . round(microtime(TRUE) - $start, 4) . ' seconds.' . PHP_EOL;$start = microtime(TRUE);for ($i = 0; $i & $count; $i++) {& & foreach ($words as $word) {& & & & if (strpos($teststring, $word) !== FALSE) {& & & & & & $find++;& & & & & && & & & }& & }}echo 'strpos - Taken ' . round(microtime(TRUE) - $start, 4) . ' seconds.' . PHP_EOL;$start = microtime(TRUE);$pattern = '/';$div = '';foreach ($words as $word) {& & $pattern .= $div . preg_quote($word);& & $div = '|';}$pattern .= '/i';for ($i = 0; $i & $count; $i++) {& & if (preg_match($pattern, $teststring)) {& & & & $find++;& & }}$end = microtime(TRUE);echo 'preg_match - Taken ' . round($end - $start, 4) . ' seconds.' . PHP_EOL;?&
highlight Search Words
&?php
function highlight($word, $subject) {
& &
& & $split_subject = explode(" ", $subject);
& & $split_word = explode(" ", $word);
& & foreach ($split_subject as $k =& $v){
& & & & && foreach ($split_word as $k2 =& $v2){
& & & & & & && if($v2 == $v){
& & & & & & & & &&
& & & & & & & & && $split_subject[$k] = "&span class='highlight'&".$v."&/span&";
& & & & & & &&
& & & & & & && }
& & & & && }
& & & }
& & &
& & & return implode(' ', $split_subject);
}
?&
i do a fair bit of html scraping in conjunction with curl. i always need to know if i have reached the right page or if the curl request failed. the main problem i have encountered is html tags having unexpected spaces or other characters (especially the & character sequence) between them. for example when requesting a page with a certain manner set of post or get variables the response might be&a href='blah'&&span&data data data&/span&&/a&but requesting the same page with different post/get variables might give the following result:&a href='blah'&& & & && &&span&data data data&/span&&/a&to match both of these tag sequences with the same pattern i use the [\S\s]*? wildcard which basically means 'match anything at all...but not if you can help it'so the pattern for the above sequence would be:&?php$page1 = "........&a href='blah'&&span&data data data&/span&&/a&.........";$page2 = "........&a href='blah'&& & & && &&span&data data data&/span&&/a&........";$w = "[\s\S]*?"; $pattern = "/\&a href='blah'\&$w\&span\&data data data\&\/span\&$w\&\/a\&/";if(preg_match($pattern, $page1, $matches)) echo "got to page 1. match: [".print_r($matches, true)."]\n";else echo "did not get to page 1\n";if(preg_match($pattern, $page2, $matches)) echo "got to page 2. match: [".print_r($matches, true)."]\n";else echo "did not get to page 2\n";?&
If someone is from a country that accepts decimal numbers in format 9.00 and 9,00 (point or comma), number validation would be like that:&?php$number_check = "9,99";if (preg_match( '/^[\-+]?[0-9]*\.*\,?[0-9]+$/', $number_check)) {& & return TRUE; }?&However, if the number will be written in the database, most probably this comma needs to be replaced with a dot. This can be done with use of str_replace, i.e :&?php$number_database = str_replace("," , "." , $number_check);?&
To support large Unicode ranges (ie: [\x{E000}-\x{FFFD}] or \x{10FFFFF}) you must use the modifier '/u' at the end of your expression.
preg_match and preg_replace_callback doesnt match up in the structure of the array that they fill-up for a match.preg_match, as the example shows, supports named patterns, whereas preg_replace_callback doesnt seem to support it at all. It seem to ignore any named pattern matched.
Preg_match returns empty result trying to validate $subject with carriege returns (/n/r).To solve it one need to use /s modifier in $pattern string.&?php$pattern='/.*/s';$valid=preg_match($pattern, $subject, $match);?&
If you need to check for .com.br and .com.au and .uk and all the other crazy domain endings i found the following expression works well if you want to validate an email address. Its quite generous in what it will allow
& & & & $email_address = "phil.taylor@a_domain.tv";
& & if (preg_match("/^[^@]*@[^@]*\.[^@]*$/", $email_address)) {
& & & & return "E-mail address";& & & &
& & }
& & & &
Validate PAN Number.[5 Alpha][4 Number][1 Alpha]AAAAA1111Afunction isValidPAN($num){& & return preg_match("/^[A-Z]{5}[0-9]{4}[A-Z]{1}$/", $num);}
The most accurate IPv4 function. It will not allow leading zeros and supports the full address range of 0.0.0.0 - 255.255.255.255&?phpfunction is_ipv4($string){& & return (bool) preg_match('/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])'.& & '\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|[0-9])$/', $string);}?&
The regular expression for breaking-down a URI reference into its components:& & & ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?& & && 12& & & & & & 3& 4& & & & & 5& & && 6& 7& & & & 8 9Source: ietf.org/rfc/rfc2396.txt
You can use the following code to detect non-latin (Cyrilic, Arabic, Greek...) characters:
&?php
preg_match("/^[a-zA-Z\p{Cyrillic}0-9\s\-]+$/u", "ABC abc 1234 АБВ абв");
?&
Always escape double quotes to avoid errors, even if you don't need to.bad practice:$foo = preg_match('/&h2 class="bengali"&.*?&\/h2&/', $bigTextChunk, $myArray);good practice:$foo = preg_match("/&h2 class=\"bengali\"&.*?&\/h2&/", bigTextChunk, $myArray);Bad practice can cause mysterious errors as it happened in my case.
I noted that PCRE_ANCHORED (the pattern modifier A) does work fine if using an offset. If you use the escape sequence \A or even the dash "^" in the regex, it does not work (even if in multiline mode)... &?php$text = 'foo bar';print (int) preg_match('/^bar/',$text,$a,null,4); print (int) preg_match('/\Abar/',$text,$a,null,4); print (int) preg_match('/bar/A',$text,$a,null,4); ?&Hope this helps someone out there! :-)Version: PHP 5.5.12
Using named subpattern :Since PCRE 7.0 ( PHP& &= 5.2.2) , named groups can be defined using (?&name&) or (?'name') instead of (?P&name&)&?php$str = 'foobar: 2008';preg_match('/(?P&name&\w+): (?P&digit&\d+)/', $str, $matches);print_r($matches);preg_match('/(?\'name\'\w+): (?\'digit\'\d+)/', $str, $matches);print_r($matches);preg_match('/(?&name&\w+): (?&digit&\d+)/', $str, $matches);print_r($matches);?&//Result Array(& & [0] =&foobar: 2008& & [name] =& foobar& & [1] =& foobar& & [digit] =& 2008& & [2] =& 2008)Array(& & [0] =& foobar: 2008& & [name] =& foobar& & [1] =& foobar& & [digit] =& 2008& & [2] =& 2008)Array(& & [0] =& foobar: 2008& & [name] =& foobar& & [1] =& foobar& & [digit] =& 2008& & [2] =& 2008)
if you want to match all printable ascii (0..127) expect some specific chars, try this:&?php$excluded = '\$a';echo preg_replace('~[^' . $excluded . '[:^print:]]~', '', 'abc123ABC!?$%/EUR');?&result: a$EUR
Attention! PREG_OFFSET_CAPTURE not UTF-8 aware when using u modifierand it's not a but, it's a feature:https://bugs.php.net/bug.php?id=37391Possible workaround: Use mb_strpos to get the correct offset, instead of the flag. UTF-8 support would be nice.
Just a note about my last post. The regex expression for the function I posted contains a question mark at the end. Technically this doesn't need to be there but it will work with or without it. Just remove it if you don't want it. Enjoy!
Simple function to return a sub-string following the preg convention. Kind of expensive, and some might say lazy but it has saved me time.# preg_substr($pattern,$subject,[$offset]) function# @author&& aer0s#& return a specific sub-string in a string using #&& a regular expression # @param&& $pattern&& regular expression pattern to match# @param&& $subject&& string to search# @param&& [$offset]&& zero based match occurrence to return#& & & & & & & & & & & & & && # [$offset] is 0 by default which returns the first occurrence,# if [$offset] is -1 it will return the last occurrence function preg_substr($pattern,$subject,$offset=0){& & preg_match_all($pattern,$subject,$matches,PREG_PATTERN_ORDER);& & return $offset==-1?array_pop($matches[0]):$matches[0][$offset];} example: & & & & & && $pattern = "/model(\s|-)[a-z0-9]/i";& & & & & && $subject = "Is there something wrong with model 654, Model 732, and model 43xl or is Model aj45B the preferred choice?";& & & & & && echo preg_substr($pattern,$subject);& & & & & && echo preg_substr($pattern,$subject,1);& & & & & && echo preg_substr($pattern,$subject,-1); Returns something like:& & & & & && model 654& & & & & && Model 732& & & & & && Model aj45B
Here's a regex to validate against the schema for common MySQL
identifiers:
&?php
$string = "$table_name";
if (preg_match("/[^\\d\\sa-zA-Z$_]/", $string))
& echo "Failed validation";
?&
When trying to check a file path that could be windows or unix it took me quite a few tries to get the escape characters right.The Unix directory separator must be escaped once and the windows directory separator must be escaped twice.This will match path/to/file and path\to\file.exepreg_match('/^[a-z0-9_.\/\\\]*$/i', $file_string);
Hello,There is a bug with somes new PCRE versions (like:7.9 ),In patterns:\w+ !== [a-zA-Z0-9]+But it's ok, if i replace \w+ by [a-z0-9]+ or [a-zA-Z0-9]+
When using accented characters and "?" (áéíóú?), preg_match does not work. It is a charset problem, use utf8_decode/decode to fix.
While I was reading the preg_match documentation I didn't found how to match an IP..Let's say you need to make a script that is working with ip/host and you want to show the hostname - not the IP.Well this is the way to go:&?php$ip = $_POST['ipOrHost'];if(preg_match('/(\d+).(\d+).(\d+).(\d+)/',$ip))& $host = gethostbyaddr($ip); else& $host = gethostbyname($ip);echo $host;?&This is a really simple script made for beginners !If you'd like you could add restriction to the numbers. The code above will accept all kind of numbers and we know that IP address could be MAX 255.255.255.255 and the example accepts to 999.999.999.999.Wish you luck!Best wishes,Steve
Html tags delete using regular expression
&?php
function removeHtmlTagsWithExceptions($html, $exceptions = null){
& & if(is_array($exceptions) && !empty($exceptions))
& & {
& & & & foreach($exceptions as $exception)
& & & & {
& & & & & & $openTagPattern& = '/&(' . $exception . ')(\s.*?)?&/msi';
& & & & & & $closeTagPattern = '/&\/(' . $exception . ')&/msi';
& & & & & & $html = preg_replace(
& & & & & & & & array($openTagPattern, $closeTagPattern),
& & & & & & & & array('||l|\1\2|r||', '||l|/\1|r||'),
& & & & & & & & $html
& & & & & & );
& & & & }
& & }
& & $html = preg_replace('/&.*?&/msi', '', $html);
& & if(is_array($exceptions))
& & {
& & & & $html = str_replace('||l|', '&', $html);
& & & & $html = str_replace('|r||', '&', $html);
& & }
& & return $html;
}
print removeHtmlTagsWithExceptions(&&&EOF
&h1&Whatsup?!&/h1&
Enjoy &span style="text-color:"&that&/span& script&br /&
&br /&
EOF
, array('br'));
?&
here is a little function to get an associative array instead of the numeric one.&?phpfunction preg_match_assoc($pattern, $subject, $assoc, $flags = 0, $offset = 0) {& & $matches = array();& & eval('preg_match($pattern, $subject, $matches, $flags, $offset);');& & $n = 0;& & foreach($matches as $result) {& & & & $array[$assoc[$n]] = $result;& & & & $n++;& & }& & return $array;}?&example of use&?php$assocs = array(& & 'all',& & 'a-1',& & 'i-1',& & 'a-2',& & 'ia-1',& & 'ia-2');$test = preg_match_assoc('#([a-z]+)([0-9]+)([a-z]+)\-([a-z|0-9]+)\-([a-z|0-9]+)#', 'az45rt-df36qz-fg89ih', $assocs);?&
I made a function to circumvent the problem of length of a string... This verifies that the link is an image.
&?php
function verifiesimage($lien, $limite) {
& & if( preg_match('#^http:\/\/(.*)\.(gif|png|jpg)$#i', $lien) && strlen($lien) & $limite )
& & {
& & & & $msg = TRUE; }
& & else
& & {
& & & & $msg = FALSE; }
& & return $msg; }
?&
&?php
if(verifierimage($votrelien, 50) == TRUE)
{
& & }
?&
The following function works well for validating ip addresses
&?php
function valid_ip($ip) {
& & return preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" .
& & & & & & "(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/", $ip);
}
?&
reading files from a dir without "." or ".."&?php$handle = opendir('content/pages/');$pages = array();while (false !== ($file = readdir($handle))) {& & & $case=preg_match("/^[.]/",$file,$out, PREG_OFFSET_CAPTURE);& & & if(!$case){& & && echo("$file&br /&");& & && array_push($pages,$file);& & && }}echo(count($pages));?&
Well for anyone looking for email validation, according to the RFC specifications (ONLY FOR ((ENGLISH ASCII)) E-Mails).
&?php
function email_valid($temp_email) {
function valid_dot_pos($email) {
& & & & & & $str_len = strlen($email);
& & & & & & for($i=0; $i&$str_len; $i++) {
& & & & & & & & $current_element = $email[$i];
& & & & & & & & if($current_element == "." && ($email[$i+1] == ".")) {
& & & & & & & & & & return false;
& & & & & & & & & &
& & & & & & & & }
& & & & & & & & else {
& & & & & & & & }
& & & & & & }
& & & & & & return true;
& & & & }
& & & & function valid_local_part($local_part) {
& & & & & & if(preg_match("/[^a-zA-Z0-9-_@.!#$%&'*\/+=?^`{\|}~]/", $local_part)) {
& & & & & & & & return false;
& & & & & & }
& & & & & & else {
& & & & & & & & return true;
& & & & & & }
& & & & }
& & & & function valid_domain_part($domain_part) {
& & & & & & if(preg_match("/[^a-zA-Z0-9@#\[\].]/", $domain_part)) {
& & & & & & & & return false;
& & & & & & }
& & & & & & elseif(preg_match("/[@]/", $domain_part) && preg_match("/[#]/", $domain_part)) {
& & & & & & & & return false;
& & & & & & }
& & & & & & elseif(preg_match("/[\[]/", $domain_part) || preg_match("/[\]]/", $domain_part)) {
& & & & & & & & $dot_pos = strrpos($domain_part, ".");
& & & & & & & & if(($dot_pos & strrpos($domain_part, "]")) || (strrpos($domain_part, "]") & strrpos($domain_part, "["))) {
& & & & & & & & & & return true;
& & & & & & & & }
& & & & & & & & elseif(preg_match("/[^0-9.]/", $domain_part)) {
& & & & & & & & & & return false;
& & & & & & & & }
& & & & & & & & else {
& & & & & & & & & & return false;
& & & & & & & & }
& & & & & & }
& & & & & & else {
& & & & & & & & return true;
& & & & & & }
& & & & }
& & & & $str_trimmed = trim($temp_email);
& & & & $at_pos = strrpos($str_trimmed, "@");
& & & & $dot_pos = strrpos($str_trimmed, ".");
& & & & $local_part = substr($str_trimmed, 0, $at_pos);
& & & & $domain_part = substr($str_trimmed, $at_pos);
& & & & if(!isset($str_trimmed) || is_null($str_trimmed) || empty($str_trimmed) || $str_trimmed == "") {
& & & & & & $this-&email_status = "You must insert something";
& & & & & & return false;
& & & & }
& & & & elseif(!valid_local_part($local_part)) {
& & & & & & $this-&email_status = "Invalid E-Mail Address";
& & & & & & return false;
& & & & }
& & & & elseif(!valid_domain_part($domain_part)) {
& & & & & & $this-&email_status = "Invalid E-Mail Address";
& & & & & & return false;
& & & & }
& & & & elseif($at_pos & $dot_pos) {
& & & & & & $this-&email_status = "Invalid E-Mail Address";
& & & & & & return false;
& & & & }
& & & & elseif(!valid_local_part($local_part)) {
& & & & & & $this-&email_status = "Invalid E-Mail Address";
& & & & & & return false;
& & & & }
& & & & elseif(($str_trimmed[$at_pos + 1]) == ".") {
& & & & & & $this-&email_status = "Invalid E-Mail Address";
& & & & & & return false;
& & & & }
& & & & elseif(!preg_match("/[(@)]/", $str_trimmed) || !preg_match("/[(.)]/", $str_trimmed)) {
& & & & & & $this-&email_status = "Invalid E-Mail Address";
& & & & & & return false;
& & & & }
& & & & else {
& & & & & & $this-&email_status = "";
& & & & & & return true;
& & & & }
}
?&

我要回帖

更多关于 p{xy=0}=1 的文章

 

随机推荐