如何用正则解析这样的字符串?
程序员文章站
2022-04-30 08:10:08
...
形如:
$str='hhhhhhhhhhhhh
'
$str='jjjjjjjjjjjjjjjj
'
想要得到p或者h1之间的内容,怎么写?
回复内容:
形如:
$str='hhhhhhhhhhhhh
'
$str='jjjjjjjjjjjjjjjj
'
想要得到p或者h1之间的内容,怎么写?
([\s\S]+?)/';
$str='hhhhhhhhhhhhh
';
preg_match($reg, $str, $result);
var_dump($result);
$str='jjjjjjjjjjjjjjjj
';
preg_match($reg, $str, $result);
var_dump($result);
运行结果:
array(3) {
[0]=>
string(20) "hhhhhhhhhhhhh
"
[1]=>
string(1) "p"
[2]=>
string(13) "hhhhhhhhhhhhh"
}
array(3) {
[0]=>
string(25) "jjjjjjjjjjjjjjjj
"
[1]=>
string(2) "h1"
[2]=>
string(16) "jjjjjjjjjjjjjjjj"
}
$reg='#(.+?)#s'