Re: including . in a pattern match



Keith Worthington wrote:

> 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


> I think what I need is the code equivilant of:
> zero or more numbers followed by

\d*

> zero or one decimal point followed by

\.?

> one or more numbers followed by

\d+

> either ' or "

['"]


Putting that together is: \d*\.?\d+['"]

which will match things like
2'
2.5'
..5'

And it's that last one that concerns me. Is no whole-number portion an
acceptable data format? If so, you're all good. If not, if the whole
number portion will always be given and the decimal will only appear if
there is a fractional portion, then what you really want is:
one or more digits, possibly followed by a decimal and one or more
digits:
\d(\.\d+)?

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

perldoc perlretut
perldoc perlre
perldoc perlreref
http://search.cpan.org/~abigail/Regexp-Common-2.120/lib/Regexp/Common/number.pm

Paul Lalli

.



Relevant Pages

  • Re: Reg Ex help...
    ... > I am trying to match only the schools name, and I have the following reg ... digits in a row but won't be limited to 3. ... use character classes such as. ...
    (perl.beginners)
  • Re: Decimal Precision error. GRRRR
    ... While the newest revision of MySQL conforms to 8.4 being 8 digits total it apparently allows less then 4 decimal points to be borrowed by the whole number portion: ... The error means the integer portion (the value discarding the decimal ...
    (microsoft.public.access.queries)
  • Re: replacing #N/A values with zero values
    ... Drop this portion completely: ... (remove the quotes) ... "Elkar" wrote: ... ERROR.TYPE function to have it return a zero in the event of #N/A and the ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Things that make me go WTF?
    ... Jngpuref are selling a product that has a 'zero' rating, ... 1/2 portion of X has Y/2 points. ... consume zero points. ... Last time I checked, a serving of carrots was assigned a value of 1 point, ...
    (alt.sysadmin.recovery)
  • Re: Profundal insight #453: arrays or lists in persistent objects fail to get cleared
    ... if you have a list or array, and attempt to zero or .clear ... another portion of your code it can still be "persistent" and non- ... another persistent object that was hanging around and had a reference ...
    (microsoft.public.dotnet.languages.csharp)