Do 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.
(written 2005-09-30 08:49:12)
Associated topics are indexed under
P212 - Perl - More on Character Strings [2657] Want to do a big batch edit? Nothing beats Perl! - (2010-03-01)
[2379] Making variables persistant, pretending a database is a variable and other Perl tricks - (2009-08-27)
[2230] Running a piece of code is like drinking a pint of beer - (2009-06-11)
[1947] Perl substitute - the e modifier - (2008-12-16)
[1735] Finding words and work boundaries (MySQL, Perl, PHP) - (2008-08-03)
[1727] Equality and looks like tests - Perl - (2008-07-29)
[1510] Handling Binary data (.gif file example) in Perl - (2008-01-17)
[1336] Ignore case in Regular Expression - (2007-09-08)
[1305] Regular expressions made easy - building from components - (2007-08-16)
[1251] Substitute operator / modifiers in Perl - (2007-06-28)
[1230] Commenting a Perl Regular Expression - (2007-06-12)
[1222] Perl, the substitute operator s - (2007-06-08)
[943] Matching within multiline strings, and ignoring case in regular expressions - (2006-11-25)
[928] C++ and Perl - why did they do it THAT way? - (2006-11-16)
[737] Coloured text in a terminal from Perl - (2006-05-29)
[608] Don't expose your regular expressions - (2006-02-15)
[597] Storing a regular expression in a perl variable - (2006-02-09)
[586] Perl Regular Expressions - finding the position and length of the match - (2006-02-02)
[583] Remember to process blank lines - (2006-01-31)
Q802 - Object Orientation and General technical topics - Regular Expression Elements [1849] String matching in Perl with Regular Expressions - (2008-10-20)
[1799] Regular Expressions in PHP - (2008-09-16)
[1766] Diagrams to show you how - Tomcat, Java, PHP - (2008-08-22)
[1480] Next course - 7th January 2008, Regular Expressions - (2007-12-21)
Some other Articles
Do the work and take the risk - a PHP contract to avoidLaying out a vegetarian lunchA Stengthening dayTime conversions in PerlCommenting Perl regular expressionsIs enough enough?Accessing a page via POST from within a PHP scriptWheelchair access - can do!Matching in MySQLOut of the norm.