Regular Expressions 101

Community Patterns

Match comments

0

Regular Expression
PCRE2 (PHP >=7.3)

/
[^#]\K#[^\n]*|^#[^\n]*
/
g

Description

This will match the comments. Example:

# hi print "Hello, World!" # hi

will be

[# hi] print "Hello, World!" [# hi]

Submitted by Fmbalbuena - 2 years ago