in reply to Pattern Matching Question
This is an excellent time to learn about a module called YAPE::Regex::Explain. With it, you can do the following:
#!/usr/bin/perl -w use strict; use YAPE::Regex::Explain; my $regex_i_dont_understand = q~"([^"]*)"~; print YAPE::Regex::Explain->new($regex_i_dont_understand)->explain; __DATA__ output: (?-imsx:"([^"]*)") matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- " '"' ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- [^"]* any character except: '"' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- " '"' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
Pretty nifty, eh? Now whenever you don't understand the way a particular regular expression works, just set $regex_i_dont_understand to it and it will explain it piece by piece.
Hope this helps.
antirice
The first rule of Perl club is - use Perl
The ith rule of Perl club is - follow rule i - 1 for i > 1
|
|---|