Y
Y
Ysery2021-08-07 12:18:51
Regular Expressions
Ysery, 2021-08-07 12:18:51

How to add exclusion tag to regex?

Good day, dear experts.

There is such a code that cuts out comments from html code.

// remove HTML comments (not containing IE conditional comments).
    $this->_html = preg_replace_callback(
      '/<!--([\\s\\S]*?)-->/'
      ,array($this, '_commentCB')
      ,$this->_html);

How to add two tag cut exception to it - <!--noindex-->and<!--/noindex-->

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-08-07
@Ysery

// remove HTML comments (not containing IE conditional comments).
    $this->_html = preg_replace_callback(
      '#<!--(?!/?noindex)(.*?)-->#s'
      ,array($this, '_commentCB')
      ,$this->_html);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question