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
30--EXPECTF--
31
32int(1)
33array(1) {
34  [0]=>
35  string(7) "Hello, "
36}
37int(0)
38array(0) {
39}
40int(1)
41array(2) {
42  [0]=>
43  string(23) "[*], this is \ a string"
44  [1]=>
45  string(18) "this is \ a string"
46}
47int(1)
48array(1) {
49  [0]=>
50  array(2) {
51    [0]=>
52    string(18) "this is \ a string"
53    [1]=>
54    int(19)
55  }
56}
57int(0)
58array(0) {
59}
60
61