[Pin to the top] do you know the syntax of nested matching in a regular expression? Please explain it to me. baidu searched a lot and couldn't understand it. I hope the gods can explain what the syntax is like. thank you! Example: (a (B (d) c) (e (f (g) m )..... I want to get (a (B (d) c) & nbsp; and & nbsp; (e (f (g) c) [pin to the top] do you know the syntax of nested matching in a regular expression?
Please explain it to me. baidu searched a lot and couldn't understand it. I hope the gods can explain what the syntax is like. thank you!
For example:
(A (B (d) c) (e (f (g) m ).....
I want to get
(A (B (d) c) and (e (f (g) c) regular expressions nested matching share:
------ Solution --------------------
$ Str = '(a (B (d) c) (e (f (g) m )';
$ Reg = '# \ ([^ \ (\)] +
------ Solution --------------------
(? R ))*\)#';
$ Matches = array ();
Preg_match_all ($ reg, $ str, $ matches );
Var_dump ($ matches );
------ Solution --------------------
Reference:
Quote: reference:
$ Str = '(a (B (d) c) (e (f (g) m )';
$ Reg = '# \ ([^ \ (\)] +
------ Solution --------------------
(? R ))*\)#';
$ Matches = array ();
Preg_match_all ($ reg, $ str, $ matches );
Var_dump ($ matches );
Can you replace the brackets with html tags and then explain them?
You directly paste your actual code to help you analyze it.
------ Solution --------------------
$ Str = '';
// $ Reg = '# \ ([^ \ (\)] +
------ Solution --------------------
(? R ))*\)#';
// Match the content of the div with id 2 and id 35
$ Reg = '# ------ solution --------------------
35) "> (<([^> \ s] +) [^>] *> ([<>] *
------ Solution --------------------
(? 1 ))*? )*#';
Preg_match_all ($ reg, $ str, $ matches );
Echo"
";
var_dump($matches);
echo "
";
Although it can be used, it is not recommended to use this method. it is better to use tools such as DOMDocument to obtain content. after all, they are better at it.