Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An excerpt from chromatic's Modern Perl book about clean regexes
# The /x modifier allows you to embed additional whitespace and comments within patterns.
# With this modifier in effect, the regex engine ignores whitespace and comments.
# The results are often much more readable.
# This regex isn't simple, but comments and whitespace improve its readability.
# Even if you compose regexes together from compiled fragments, the /x modifier
# can still improve your code.
my $attr_re = qr{
\A # start of line
(?:
[;\n\s]* # spaces and semicolons
(?:/\*.*?\*/)? # C comments
)*
ATTR
\s+
( U?INTVAL
| FLOATVAL
| STRING\s+\*
)
}x;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.