Php Regex find所有单词都以两个斜杠开头

Php Regex find所有单词都以两个斜杠开头,php,regex,pattern-matching,Php,Regex,Pattern Matching,我想找到标记后以两个斜杠开头的所有字符 例如:- http://www // this is first comment <body> <div> // this is comment <p>//this is another comment. 但不是: //www // this is first comment 这只是一个例子,它可能还包含数字和括号。 语言php只需要正则表达式您可以使用以下模式: (?<!http:)\/\/(\s?[\w\.

我想找到标记后以两个斜杠开头的所有字符 例如:-

http://www
// this is first comment
<body>
<div>
// this is comment
<p>//this is another comment.
但不是:

//www
// this is first comment
这只是一个例子,它可能还包含数字和括号。
语言php只需要正则表达式

您可以使用以下模式:

(?<!http:)\/\/(\s?[\w\.])+

您可以使用此模式执行此操作:

(?<!http:)\/\/(\s?[\w\.])+

您可以使用以下PHP代码:

$html = <<< EOF
http://www
// this is first comment
<body>
<div>
// this is comment
<p>//this is another comment.
EOF;

您可以使用以下PHP代码:

$html = <<< EOF
http://www
// this is first comment
<body>
<div>
// this is comment
<p>//this is another comment.
EOF;

@DavidThomas非常感谢,我太累了。@DavidThomas非常感谢,我太累了。我不考虑http。我只是举个例子。因此,不要匹配任何位于正文上方且具有forwardslashI的内容。我猜您必须提取节点,然后使用正则表达式搜索注释,因为使用正则表达式执行“after”操作没有意义。@Adamwalski很好,有一种方法可以忽略标记之前的所有内容,只需选择//。是,有这样一种方法,但它实际上类似于通过正则表达式解析HTML。而且很糟糕!我不考虑http。我只是举个例子。因此,不要匹配任何位于正文上方且具有forwardslashI的内容。我猜您必须提取节点,然后使用正则表达式搜索注释,因为使用正则表达式执行“after”操作没有意义。@Adamwalski很好,有一种方法可以忽略标记之前的所有内容,只需选择//。是,有这样一种方法,但它实际上类似于通过正则表达式解析HTML。而且很糟糕!
$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.
        )

)