Useful Regular Expressions

Just a place to dump some useful regexps.

Sometime soon, grab the tables of char classes from: http:piglet.uccs.edu/~cs301/perl/re.htm to make a new page. ===== Parsing Apache Logfiles ===== This has been done too many times before. Have a look on CPAN for modules to do it. But, for quick simple scripts where it's not worth getting + installing modules: Parses the date field of an Apache common logfile format log (e.g [01/Nov/2006:13:23:30 +0000]): <code perl> my ($date,$day,$month,$year, $time, $hour, $min, $sec, $tz) = $line =~ m{ \[( ( \d{2} ) / ( \w{3} ) / ( \d{4} ) ) # day, month, year : ( ( \d{2} ) : ( \d{2} ) : ( \d{2} ) ) # hour, min, sec \s ([+-]\d{4}) # timezone }xms; </code> It's a beauty :) ~~DISCUSSION~~

 
perl/usefulregexps.txt · Last modified: 2010/02/26 10:45 (external edit)
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki