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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.