in reply to Angle brackets and regex problem
You've told it to match one character not an > (which 1 is), one or more digits (which 3 is), zero or more lower case letters (which nothing is), and one character that's not < (which a is). Wherein lies the problem?
And of course there's the standard jibe that in general you want to use something like HTML::TreeBuilder or the like to parse HTML, not regexen.
Update: Curse you, Red Baronmerlyn. :)
And a hopefully useful pointer: YAPE::Regex::Explain can be helpful for obtaining a prose explanation of just what your regex means. Using it on your regex produces this:
perl -MYAPE::Regex::Explain -le 'print YAPE::Regex::Explain->new( qr/( +[^>]\d+[a-z]*[^<])/ )->explain' The regular expression: (?-imsx:([^>]\d+[a-z]*[^<])) 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: '>' ---------------------------------------------------------------------- \d+ digits (0-9) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- [a-z]* any character of: 'a' to 'z' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- [^<] any character except: '<' ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Angle brackets and regex problem
by emav (Pilgrim) on Jan 05, 2007 at 17:36 UTC | |
by ikegami (Patriarch) on Jan 05, 2007 at 17:40 UTC |