[英]Regex find all words start with two slashes
我想在<body>
标签示例之后找到所有以两个斜杠开头的字符:-
http://www
// this is first comment
<body>
<div>
// this is comment
<p>//this is another comment.
所以我想同时匹配:
// this is comment.
//this is another comment.
但不是:
//www
// this is first comment
这仅是示例,它可能还包含数字和括号。 语言PHP只想要正则表达式
您可以使用以下PHP代码:
$html = <<< EOF
http://www
// this is first comment
<body>
<div>
// this is comment
<p>//this is another comment.
EOF;
if (preg_match_all('~//(?!.*?<body>)[^\n]*~is', $html, $arr))
print_r($arr);
$html = preg_replace('#^.*?<body>#is', '', $html);
if (preg_match_all('~//[^\n]*~', $html, $arr))
print_r($arr);
Array
(
[0] => Array
(
[0] => // this is comment
[1] => //this is another comment.
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.