Created
January 17, 2014 02:37
-
-
Save smonff/8467532 to your computer and use it in GitHub Desktop.
An excerpt from chromatic's Modern Perl book about clean regexes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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