1--TEST--
2Test preg_match() function : basic functionality
3--FILE--
4<?php
5/*
6 *  proto int preg_match(string pattern, string subject [, array subpatterns [, int flags [, int offset]]])
7 * Function is implemented in ext/pcre/php_pcre.c
8*/
9$string = 'Hello, world. [*], this is \ a string';
10var_dump(preg_match('/^[hH]ello,\s/', $string, $match1)); //finds "Hello, "
11var_dump($match1);
12var_dump(preg_match('/l^o,\s\w{5}/', $string, $match2, PREG_OFFSET_CAPTURE)); // tries to find "lo, world" at start of string
13var_dump($match2);
14var_dump(preg_match('/\[\*\],\s(.*)/', $string, $match3)); //finds "[*], this is \ a string";
15var_dump($match3);
16var_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)
17var_dump($match4);
18var_dump(preg_match('/hello world/', $string, $match5)); //tries to find "hello world" (should be Hello, world)
19var_dump($match5);
20?>
21
22--EXPECTF--
23
24int(1)
25array(1) {
26  [0]=>
27  string(7) "Hello, "
28}
29int(0)
30array(0) {
31}
32int(1)
33array(2) {
34  [0]=>
35  string(23) "[*], this is \ a string"
36  [1]=>
37  string(18) "this is \ a string"
38}
39int(1)
40array(1) {
41  [0]=>
42  array(2) {
43    [0]=>
44    string(18) "this is \ a string"
45    [1]=>
46    int(19)
47  }
48}
49int(0)
50array(0) {
51}
52
53