A regular expression problem
$string='dj%a3%a3999';if(preg_match('/^[dj]{2}([(\%23)(\%a3\%a3)])((\w)+)$/i', $string,$result)){ print_r($result);}
There is no matching solution.
Reply to discussion (solution)
You 'd better talk about your requirements. The middle section shows that your regular expressions are messy.
/* The requirement is that one dj group % a3 % a3 or % 23 is another group. 999 is a group that obtains the corresponding data through $ result. For example: */$ result [0] = 'DJ'; $ result [1] = '% a3 % a3'; $ result [2] = '2016 ';
$s = 'dj%a3%a3999';preg_match('/([^%]+)((?:%a3|23)+)(.+)/', $s, $r);print_r($r);Array ([0] => dj % a3 % a3999 [1] => dj [2] => % a3 % a3 [3] => 999)
This is used:
$string='dj%a3%a3999';if(preg_match('/^([dj]{2})([%a3]+)(\d{3})$/i', $string,$result)){ print_r($result);}
Result:
Array ( [0] => dj%a3%a3999 [1] => dj [2] => %a3%a3 [3] => 999 )
$s = 'dj%a3%a3999';preg_match('/([^%]+)((?:%a3|23)+)(.+)/', $s, $r);print_r($r);Array ([0] => dj % a3 % a3999 [1] => dj [2] => % a3 % a3 [3] => 999)
If $ s = 'DJ % 100'; then no.
This is used:
$string='dj%a3%a3999';if(preg_match('/^([dj]{2})([%a3]+)(\d{3})$/i', $string,$result)){ print_r($result);}
[/Code]
This string also needs to match: $ string = 'DJ % 100 ';
$ S = 'DJ % 8080 ';
Preg_match ('/([^ %] + )((? : % (? : A3 | 23) +) (. +)/', $ s, $ r );
Or
Preg_match ('/([^ %] + )((? : % A3 | % 23) +) (. +)/', $ s, $ r );
Regular expression rules are described as follows:
| If ambiguity occurs during calculation, you must list them one by one or enclose them in parentheses.
Apparently (? % A3 | 23). % is combined with a3, causing ambiguity.
Boss, can you help me explain that I see many regular expressions added in front of them? : I want to know what this means?
(? :...) Is the same as (...) grouping, but the result does not show a result set.
(? :...) Is the same as (...) grouping, but the result does not show a result set.
Boss, can you match an address for me? for example:
Www.sohu.com, www.baidu.com, www.yahoo.com. n
In this way, a maximum of nine URLs can be connected, including sohu.com, baidu.com, and yahoo.com.cn.
(?! (W) (\ w + (-\ w +) *) (\. (\ w + (-\ w + )*))*