1--TEST-- 2Test preg_match() function : basic functionality 3--FILE-- 4<?php 5/* Prototype : proto int preg_match(string pattern, string subject [, array subpatterns [, int flags [, int offset]]]) 6 * Description: Perform a Perl-style regular expression match 7 * Source code: ext/pcre/php_pcre.c 8 * Alias to functions: 9*/ 10 11 12$string = 'Hello, world. [*], this is \ a string'; 13 14var_dump(preg_match('/^[hH]ello,\s/', $string, $match1)); //finds "Hello, " 15var_dump($match1); 16 17var_dump(preg_match('/l^o,\s\w{5}/', $string, $match2, PREG_OFFSET_CAPTURE)); // tries to find "lo, world" at start of string 18var_dump($match2); 19 20var_dump(preg_match('/\[\*\],\s(.*)/', $string, $match3)); //finds "[*], this is \ a string"; 21var_dump($match3); 22 23var_dump(preg_match('@\w{4}\s\w{2}\s\\\(?:\s.*)@', $string, $match4, PREG_OFFSET_CAPTURE, 14)); //finds "this is \ a string" (with non-capturing parentheses) 24var_dump($match4); 25 26var_dump(preg_match('/hello world/', $string, $match5)); //tries to find "hello world" (should be Hello, world) 27var_dump($match5); 28?> 29--EXPECT-- 30int(1) 31array(1) { 32 [0]=> 33 string(7) "Hello, " 34} 35int(0) 36array(0) { 37} 38int(1) 39array(2) { 40 [0]=> 41 string(23) "[*], this is \ a string" 42 [1]=> 43 string(18) "this is \ a string" 44} 45int(1) 46array(1) { 47 [0]=> 48 array(2) { 49 [0]=> 50 string(18) "this is \ a string" 51 [1]=> 52 int(19) 53 } 54} 55int(0) 56array(0) { 57} 58