The regular expression used to obtain substrings has the following strings: & quot; & lt; str1 & gt; name1 & lt;/str1 & gt; & lt; str2 & gt; name2 & lt; /str2 & gt; & quot; how do I retrieve & quot; name1 & quot; and & quot; name2 & quot; using regular expressions? Thank you. use PHPcode to obtain the regular expression of the substring.
There are the following strings:
" Name1 Name2 "
How can I retrieve "name1" and "name2" using regular expressions? Thank you.
------ Solution --------------------
PHP code
Name1
Name2
"; $ Patten = "/
([^ <] *) <\/Str \ d +>/isU "; preg_match_all ($ patten, $ str, $ matches); print_r ($ matches [1]);
------ Solution --------------------
PHP code
$ Str ="
Name1
Name2
"; Preg_match_all ('/> ([^ <] +)Name1 [1] => name2 )*/
------ Solution --------------------
PHP code
Preg_match_all ("/> [^ <] +
------ Solution --------------------
$ Str ="
Name1
Name2
";
Preg_match_all ('/> ([^ <] +)Print_r ($ matches [1]);
/**
Output result:
Array ([0] => name1 [1] => name2)
*/
------ Solution --------------------
PHP code
Name1
Name2
"; $ Preg = "#
(.*)
(.*)
# "; Preg_match ($ preg, $ str, $ arr); echo $ arr [1]; echo $ arr [2];?>
------ Solution --------------------
$ Str ="
Name1
Name2
";
Preg_match_all ("/<[a-z0-9] *> ([^ <|>] *) <\/[a-z0-9] *>/", $ str, $ matches );
Echo $ matches [1] [0];
Echo $ matches [1] [1];
?>
------ Solution --------------------
"/> (.*?) <\//"
------ Solution --------------------
Discussion
PHP code
$ Str ="
Name1
Name2
";
Preg_match_all ('/> ([^ <] +)Print_r ($ matches [1]);
/**
Output result:
Array ([0] => name1 [1] => name2)
*/
------ Solution --------------------
$ Str ="
Name1
Name2
";
Preg_match_all ("/<[a-z0-9] *> ([^ <|>] *) <\/[a-z0-9] *>/", $ str, $ matches );
Echo $ matches [1] [0];
Echo $ matches [1] [1];
?>