欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

如何用正则解析这样的字符串?

程序员文章站 2022-04-30 09:16:59
...
形如:
$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'