Ask a question about a regular expression ..... There is a character string: [ti: shuang hua concentrated] [ar: Xiao Qu er] [al:] [by: Wen Chao] I want to match the following two strings: [ti: the code I wrote is as follows: PHPcode $ pattern = '/[t ask you a question about a regular expression .....
There is a character string: [ti: shuang hua concentrated] [ar: Xiao Qu er] [al:] [by: Wen Chao]
I want to match the following items: [ti: Shuang Huaqiang], [ar: Xiao Qu er], [al:], and by: Wen Chao]
The code I wrote is as follows:
PHP code
$pattern = '/[ti:.*].*?]/is';preg_match_all($pattern, $str, $match); echo '';var_dump($match);echo '
';
The printed result is:
Array (1 ){
[0] =>
Array (5 ){
[0] =>
String (10) "ti: frommon]"
[1] =>
String (8) ": Xiao Qu er]"
[2] =>
String (2) ":]"
[3] =>
String (6) ": Wen Chao]"
[4] =>
String (14) "t_time :( :47)]"
}
}
Then I changed the regular expression to: $ pattern = '/\ [ti:. *]. *?]. /Is ';
The matching result is:
Array (1 ){
[0] =>
Array (1 ){
[0] =>
String (51) "[ti: frommon] [ar: Xiao Qu er] [al:] [by: Wen Chao] [t_time :( :47)]"
}
Where did I go wrong?
How should I write the correct one?
Thank you!
}
------ Solution --------------------
What does this mean?
PHP code
$ S = '[ti: shuang hua Nong] [ar: Xiao Qu er] [al:] [by: Wen Chao]'; preg_match_all ('/\ [^] + \]/', $ s, $ r); print_r ($ r [0]);