Commenting Perl regular expressions
Archive - Originally posted on "The Horse's Mouth" - 2005-09-30 08:49:12 - Graham EllisDo you sometimes find Perl regular expressions hard to follow? If you do, remember that you can use the "x" modifier which allows you to space them out; with the "x" modifier, white spaces in the regular expression are ignored.
You can go further; once you've specified the "x" modifier, you can embed comments in your regular expression - for example:
@cliad = ($log =~ /^ # line starts with
.* # any characters
cliad # then literally look for "cliad"
.* # then look for any characters
$ # up to a line end
/xmg);
See our regular expression course and resources to learn more about regular expressions.