Re: including . in a pattern match
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 27 Jan 2006 13:17:36 -0800
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
.
- References:
- including . in a pattern match
- From: Keith Worthington
- including . in a pattern match
- Prev by Date: including . in a pattern match
- Next by Date: Re: including . in a pattern match
- Previous by thread: including . in a pattern match
- Next by thread: Re: including . in a pattern match
- Index(es):
Relevant Pages
|