Community Patterns

Community Library Entry

0

Regular Expression
Created·2023-01-30 13:50
Flavor·PCRE (Legacy)

/
<!--(?:(?!<!--|-->).|(?R))*-->
/
gs
Open regex in editor

Description

Even if this is not valid HTML, it's more to understand the concept of recursion in patterns.

It was an answer to a Stack overflow question: https://stackoverflow.com/questions/75282404/remove-comments-from-some-generated-html-which-can-be-invalid-with-nested-commen

The idea is to use PCRE's recursive pattern to solve the problem.

Submitted by Patrick Janser