Reputation: 1911
I want to find all the characters that start with two slashes after <body>
tag
example:-
http://www
// this is first comment
<body>
<div>
// this is comment
<p>//this is another comment.
so I want to match both:
// this is comment.
//this is another comment.
but not:
//www
// this is first comment
This is just example it might also contains digits and brackets. language php just want regex
Upvotes: 1
Views: 417
Reputation: 785406
You can use this PHP code:
$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.
)
)
Upvotes: 4