in reply to newline in pattern matching

This pattern succesfully matches all of the sample lines.
my $dist = $1 if ($str =~ /dist:.([0-9]+)/s );

Your regex IS getting the numerical part of string, but it is capturing the newlines with it as well. Maybe this fact is what is causing you problems?
Wonko

Replies are listed 'Best First'.
Re: Re: newline in pattern matching
by Anonymous Monk on Nov 15, 2002 at 20:13 UTC
    Hi Everyone. I've tried your suggestions (and combos of) and the one that seems to work best is

    (/dist:.(\d+)/s)

    The only case I haven't gotten this one to work on is:

    dist:
    45.3 km;

    Any suggestions?

    I should have mentioned earlier that the number involved is a real number and that I'm reading these numbers from an input data file. Right now, only the integer part of the number is being read. I'm in the process of looking up how to handle that one right now. Thanks again!
      You're really close. Try this:
      ( /dist:.*([\d.]+)/s )
      Note that the period, when inside square brackets, is treated as a literal, not as a wildcard.