1--TEST--
2testing /r modifier in preg_* functions
3--SKIPIF--
4<?php
5if (PCRE_VERSION_MAJOR == 10 && PCRE_VERSION_MINOR < 43) {
6    die("skip old pcre version");
7}
8?>
9--FILE--
10<?php
11echo "SK substitute matching" . PHP_EOL;
12var_dump(preg_match('/AskZ/iur', 'AskZ')); // match
13var_dump(preg_match('/AskZ/iur', 'aSKz')); // match
14var_dump(preg_match('/AskZ/iur', "A\u{17f}kZ")); // no match
15var_dump(preg_match('/AskZ/iur', "As\u{212a}Z")); // no match
16var_dump(preg_match('/AskZ/iu', 'AskZ')); // match
17var_dump(preg_match('/AskZ/iu', 'aSKz')); // match
18var_dump(preg_match('/AskZ/iu', "A\u{17f}kZ")); // match
19var_dump(preg_match('/AskZ/iu', "As\u{212a}Z")); // match
20
21echo "K substitute matching" . PHP_EOL;
22var_dump(preg_match('/k/iu', "\u{212A}"));
23var_dump(preg_match('/k/iur', "\u{212A}"));
24
25echo "non-ASCII in expressions" . PHP_EOL;
26var_dump(preg_match('/A\x{17f}\x{212a}Z/iu', 'AskZ')); // match
27var_dump(preg_match('/A\x{17f}\x{212a}Z/iur', 'AskZ')); // no match
28
29echo "Character sets" . PHP_EOL;
30var_dump(preg_match('/[AskZ]+/iur', 'AskZ')); // match
31var_dump(preg_match('/[AskZ]+/iur', 'aSKz')); // match
32var_dump(preg_match('/[AskZ]+/iur', "A\u{17f}kZ")); // match
33var_dump(preg_match('/[AskZ]+/iur', "As\u{212a}Z")); // match
34var_dump(preg_match('/[AskZ]+/iu', 'AskZ')); // match
35var_dump(preg_match('/[AskZ]+/iu', 'aSKz')); // match
36var_dump(preg_match('/[AskZ]+/iu', "A\u{17f}kZ")); // match
37var_dump(preg_match('/[AskZ]+/iu', "As\u{212a}Z")); // match
38
39echo "non-ASCII in character sets" . PHP_EOL;
40var_dump(preg_match('/[\x{17f}\x{212a}]+/iur', 'AskZ')); // no match
41var_dump(preg_match('/[\x{17f}\x{212a}]+/iu', 'AskZ')); // match
42
43echo "Meta characters and negate character sets". PHP_EOL;
44var_dump(preg_match('/[^s]+/iur', "A\u{17f}Z")); // match
45var_dump(preg_match('/[^s]+/iu', "A\u{17f}Z")); // match
46var_dump(preg_match('/[^s]+/iu', "A\u{17f}Z")); // match
47var_dump(preg_match('/[^k]+/iur', "A\u{212a}Z")); // match
48var_dump(preg_match('/[^k]+/iu', "A\u{212a}Z")); // match
49var_dump(preg_match('/[^sk]+/iur', "A\u{17f}\u{212a}Z")); // match
50var_dump(preg_match('/[^sk]+/iu', "A\u{17f}\u{212a}Z")); // match
51var_dump(preg_match('/[^\x{17f}]+/iur', "AsSZ")); // match
52var_dump(preg_match('/[^\x{17f}]+/iu', "AsSZ")); // match
53
54echo "Modifier used within the expression" . PHP_EOL;
55var_dump(preg_match('/s(?r)s(?-r)s(?r:s)s/iu', "\u{17f}S\u{17f}S\u{17f}")); // match
56var_dump(preg_match('/s(?r)s(?-r)s(?r:s)s/iu', "\u{17f}\u{17f}\u{17f}S\u{17f}")); // no match
57var_dump(preg_match('/s(?r)s(?-r)s(?r:s)s/iu', "\u{17f}S\u{17f}\u{17f}\u{17f}")); // no match
58var_dump(preg_match('/k(?^i)k/iur', "K\u{212a}")); // match
59var_dump(preg_match('/k(?^i)k/iur', "\u{212a}\u{212a}")); // no match
60
61echo "Done";
62?>
63--EXPECT--
64SK substitute matching
65int(1)
66int(1)
67int(0)
68int(0)
69int(1)
70int(1)
71int(1)
72int(1)
73K substitute matching
74int(1)
75int(0)
76non-ASCII in expressions
77int(1)
78int(0)
79Character sets
80int(1)
81int(1)
82int(1)
83int(1)
84int(1)
85int(1)
86int(1)
87int(1)
88non-ASCII in character sets
89int(0)
90int(1)
91Meta characters and negate character sets
92int(1)
93int(1)
94int(1)
95int(1)
96int(1)
97int(1)
98int(1)
99int(1)
100int(1)
101Modifier used within the expression
102int(1)
103int(0)
104int(0)
105int(1)
106int(0)
107Done
108