darisler has asked for the wisdom of the Perl Monks concerning the following question:
I am trying code a regular expression which will capture an "unsigned fixed decimal" value, preserving the original formatting. Here is what I'm trying to do:
When I run this I get the following:my $decimal = qr(\d*\.?\d+); $_ = "0.12"; if ( m{(?<value> $decimal)}x ) { say "$_ $+{value}"; } $_ = ".12"; if ( m{(?<value> $decimal)}x ) { say "$_ $+{value}"; } $_ = "12."; if ( m{(?<value> $decimal)}x ) { say "$_ $+{value}"; } $_ = "12"; if ( m{(?<value> $decimal)}x ) { say "$_ $+{value}"; }
0.12 0.12 .12 .12 12. 12 12 12
But the third line, I am not preserving the trailing decimal place, although the values should be equal.
Can anyone point out how I could change my "qr" so that it "works" for the third line?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex to capture an unsigned decimal value, but also preserving the user's formatting.
by davido (Cardinal) on May 04, 2016 at 05:57 UTC | |
by Athanasius (Archbishop) on May 04, 2016 at 06:41 UTC | |
by davido (Cardinal) on May 04, 2016 at 15:00 UTC | |
by AnomalousMonk (Archbishop) on May 04, 2016 at 14:47 UTC |