1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
--TEST--
abusing pcre
--FILE--
<?php
var_dump(preg_match_all('/((?:(?:unsigned|struct)\s+)?\w+)(?:\s*(\*+)\s+|\s+(\**))(\w+(?:\[\s*\w*\s*\])?)\s*(?:(=)[^,;]+)?((?:\s*,\s*\**\s*\w+(?:\[\s*\w*\s*\])?\s*(?:=[^,;]+)?)*)\s*;/S', 'unsigned int xpto = 124; short a, b;', $m, PREG_SET_ORDER));
var_dump($m);
var_dump(preg_match_all('/(?:\([^)]+\))?(&?)([\w>.()-]+(?:\[\w+\])?)\s*,?((?:\)*\s*=)?)/S', '&a, b, &c', $m, PREG_SET_ORDER));
var_dump($m);
var_dump(preg_match_all('/zend_parse_parameters(?:_ex\s*\([^,]+,[^,]+|\s*\([^,]+),\s*"([^"]*)"\s*,\s*([^{;]*)/S', 'zend_parse_parameters( 0, "addd|s/", a, b, &c);', $m, PREG_SET_ORDER | PREG_OFFSET_CAPTURE));
var_dump($m);
var_dump(preg_split('/PHP_(?:NAMED_)?(?:FUNCTION|METHOD)\s*\((\w+(?:,\s*\w+)?)\)/S', "PHP_FUNCTION(s, preg_match)\n{\nlalala", -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE));
?>
--EXPECT--
int(2)
array(2) {
[0]=>
array(7) {
[0]=>
string(24) "unsigned int xpto = 124;"
[1]=>
string(12) "unsigned int"
[2]=>
string(0) ""
[3]=>
string(0) ""
[4]=>
string(4) "xpto"
[5]=>
string(1) "="
[6]=>
string(0) ""
}
[1]=>
array(7) {
[0]=>
string(11) "short a, b;"
[1]=>
string(5) "short"
[2]=>
string(0) ""
[3]=>
string(0) ""
[4]=>
string(1) "a"
[5]=>
string(0) ""
[6]=>
string(3) ", b"
}
}
int(3)
array(3) {
[0]=>
array(4) {
[0]=>
string(3) "&a,"
[1]=>
string(1) "&"
[2]=>
string(1) "a"
[3]=>
string(0) ""
}
[1]=>
array(4) {
[0]=>
string(2) "b,"
[1]=>
string(0) ""
[2]=>
string(1) "b"
[3]=>
string(0) ""
}
[2]=>
array(4) {
[0]=>
string(2) "&c"
[1]=>
string(1) "&"
[2]=>
string(1) "c"
[3]=>
string(0) ""
}
}
int(1)
array(1) {
[0]=>
array(3) {
[0]=>
array(2) {
[0]=>
string(46) "zend_parse_parameters( 0, "addd|s/", a, b, &c)"
[1]=>
int(0)
}
[1]=>
array(2) {
[0]=>
string(7) "addd|s/"
[1]=>
int(27)
}
[2]=>
array(2) {
[0]=>
string(9) "a, b, &c)"
[1]=>
int(37)
}
}
}
array(3) {
[0]=>
array(2) {
[0]=>
string(0) ""
[1]=>
int(0)
}
[1]=>
array(2) {
[0]=>
string(13) "s, preg_match"
[1]=>
int(13)
}
[2]=>
array(2) {
[0]=>
string(9) "
{
lalala"
[1]=>
int(27)
}
}
|