PHP正则表达式与换行符与s修饰符不匹配
发布时间:2020-12-13 17:46:17 所属栏目:PHP教程 来源:网络整理
导读:我试图匹配跨越2行的一系列单词. 说我有以下文字: this is a testanother line 我使用preg_match的正则表达式模式: /test.*another/si 在这里测试: http://www.phpliveregex.com/p/2zj PHP模式修饰符: http://php.net/manual/en/reference.pcre.pattern.
我试图匹配跨越2行的一系列单词.
说我有以下文字: this is a test another line 我使用preg_match的正则表达式模式: /test.*another/si 在这里测试: PHP模式修饰符: 我读过的所有内容都指向使用“s”修饰符来启用“.”.字符匹配新行,但我不能让这个工作.有任何想法吗? 解决方法
你的正则表达式是正确的,并在我的本地机器上正常工作:
$input_line = "this is a test another line"; preg_match("/test.*another/si",$input_line,$output_array); var_dump($output_array); 它产生以下输出: array(1) { [0]=> string(13) "test another" } 所以我的猜测是phpliveregex.com运行不正常并给你错误的结果. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |