Most problems cause those lines that have 4 or 8 spaces before the searched word as in my example. Problem number two is how to remove all but the version number (here 0.11) from that line,You're looking for a match, not a substitution. Here's how I'd do it (even if i really have no clue what you're trying to do, perhaps you ought to investigate perlfunc:split, and perhaps define the data you're processing better).
use strict; use warnings; my @LINES = ( " VERSION: 0.11 12-Jul-2002 HWe", " aaaa#VERSION: 0.11 12-Jul-2002 HWe", " aaaa;VERSION: 0.11 12-Jul-2002 HWe", ); for my $L ( @LINES ) { print "We got VERSION $1\n" if $L =~ m{ VERSION: # literal \s+ # followed by 1 or more space (\S+) # non-space 1 or more, captured to $1 \s # followed by a space }ix; # ignore case, use extended patterns } eval q{ require YAPE::Regex::Explain; print "\n", YAPE::Regex::Explain->new( qr[VERSION: \s+ (\S+) \s]ix )->explain; }; print $@ if $@; __END__ # ran as `perl oy>>oy' We got VERSION 0.11 We got VERSION 0.11 We got VERSION 0.11 The regular expression: (?ix-ms:VERSION: \s+ (\S+) \s) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?ix-ms: group, but do not capture (case-insensitive) (disregarding whitespace and comments) (with ^ and $ matching normally) (with . not matching \n): ---------------------------------------------------------------------- VERSION: 'VERSION:' ---------------------------------------------------------------------- \s+ whitespace (\n, \r, \t, \f, and " ") (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- \S+ non-whitespace (all but \n, \r, \t, \f, and " ") (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- \s whitespace (\n, \r, \t, \f, and " ") ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
____________________________________________________
** The Third rule of perl club is a statement of fact: pod is sexy.
In reply to Re: Matching characters
by PodMaster
in thread Matching characters
by hewarn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |