including . in a pattern match



Hi All,

I am still a newbie in Perl and it is only with the help of this list that I was
able to construct the following pattern match.

($v_size_str =~ /\d+\s*['"]\s*x\s*\d+\s*['"]/i)

The problem that I have just realized that this string will match the first line
of this input file but not the second.

Border: None Size: 2.5' x 10' Tag: None
Border: None Size: 10' x 2.5' Tag: None

Here is the test perl script.
#!/usr/bin/env perl
use strict;
use warnings;

open(INFILE, "small_input.txt") or die "Can't open input.txt: $!";

while (<INFILE>) { # assigns each line in turn to $_
my $v_border_id = "";
my $v_dim1_total = 0;
my $v_dim2_total = 0;
my $v_tag = "";

# Echo out the input line.
print "\nInput line: $_";
# Perform a case insensitive check for the proper data format. Capture the
# desired parts of the data using parentheses.
if (/.*border:\s*(.*?)\s*size:\s*(.*?)\s*tag:\s*(.*)\s*/i){
print "properly formatted\n";
# Store the capture patterns in variables to avoid unpredictable results.
my ($v_border_str, $v_size_str, $v_tag_str) = ($1, $2, $3);
# Parse up the size string.
if ($v_size_str =~ /\d+\s*['"]\s*x\s*\d+\s*['"]/i){
print "It looks like a size string.\n";
} else {
print "It doesn't look like a size string.\n";
}
} else {
print "bad format\n";
$v_border_id = "";
$v_dim1_total = 0;
$v_dim2_total = 0;
$v_tag = "";
}
}

close INFILE;

Okay so the pattern is able to ignore a decimal in the first dimesion because it
only needs one digit before the unit indicator. On the right it is trying to
match the whole thing so I need something to match the potential decimal point.
I have tried a couple of things but I am struggling with how to optionally
match the decimal point.

I think what I need is the code equivilant of:
zero or more numbers followed by
zero or one decimal point followed by
one or more numbers followed by
either ' or "

I appreciate your time in giving me some help with this issue. URL's to
documentation are welcome.

Kind Regards,
Keith
.



Relevant Pages

  • Re: pattern matching question - please help
    ... Thanks for your detailed email and for your time. ... read on Perl did not mention anything about first and ... >> the pattern match ... a single character (basically, see references ...
    (perl.beginners)
  • FAQ 6.23 How do I match a regular expression thats in a variable?
    ... How do I match a regular expression that's in a variable? ... We don't have to hard-code patterns into the match operator (or anything ... have the pattern in $regex, you use that variable in the match operator. ... and the pattern still has to be valid or Perl will complain. ...
    (comp.lang.perl.misc)
  • FAQ 6.23 How do I match a regular expression thats in a variable?
    ... How do I match a regular expression that's in a variable? ... We don't have to hard-code patterns into the match operator (or anything ... have the pattern in $regex, you use that variable in the match operator. ... and the pattern still has to be valid or Perl will complain. ...
    (comp.lang.perl.misc)
  • FAQ 6.23 How do I match a regular expression thats in a variable?
    ... How do I match a regular expression that's in a variable? ... We don't have to hard-code patterns into the match operator (or anything ... have the pattern in $regex, you use that variable in the match operator. ... and the pattern still has to be valid or Perl will complain. ...
    (comp.lang.perl.misc)
  • FAQ 6.23 How do I match a regular expression thats in a variable?
    ... How do I match a regular expression that's in a variable? ... We don't have to hard-code patterns into the match operator (or anything ... have the pattern in $regex, you use that variable in the match operator. ... and the pattern still has to be valid or Perl will complain. ...
    (comp.lang.perl.misc)