On Jul 13, Gunnar Hjalmarsson said:
>Jeff 'Japhy' Pinyan wrote:
>
>> /(-?(?=.?\d)\d*\.?\d*)/
>
>I disagree.
>
>- It has almost as many characters.
>- It's more difficult to read/understand.
>- It's slower (see benchmark below).
Aww, shucks. Fine. My attempts have failed.
--
Jeff "japhy" Pin
Randy W. Sims wrote:
Gunnar Hjalmarsson wrote:
use warnings;
use Regexp::Common 'number';
$_ = '.';
/^$RE{num}{real}$/ and print "\"$_\" is a number.\n";
my $x = 1 if $_ < 5;
Outputs:
"." is a number.
"." isn't numeric in numeric lt (<) at ...
Regexp::Common considers an alone d
Jeff 'Japhy' Pinyan wrote:
I've seen the response of /-?(?:\d+\.?\d*|\.\d+)/, and while that
does work, it seems too noisy to me. What we would really like to
be able to say is /-?\d*\.?\d*/, but you should be able to see that
could match "-." and "." and "", which we decided aren't legitimite
num
On Jul 11, Jeff 'japhy' Pinyan said:
>I tend to write that as /(-?\d+\.?\d*)/, but be aware that this doesn't
>match numbers like .52 or .9, because they don't have digits BEFORE the
>decimal point.
I've seen the response of /-?(?:\d+\.?\d*|\.\d+)/, and while that does
work, it seems too noisy to
Gunnar Hjalmarsson wrote:
Randy W. Sims wrote:
Jerry Preston wrote:
What needs to be changed in /(-?\d+\.?\d*)/ so that it also see
number like .59?
This is why I like to recommend Regexp::Common. But...
use warnings;
use Regexp::Common 'number';
$_ = '.';
/^$RE{num}{real}$/ and p
Randy W. Sims wrote:
Jerry Preston wrote:
What needs to be changed in /(-?\d+\.?\d*)/ so that it also see
number like .59?
This is why I like to recommend Regexp::Common. But...
use warnings;
use Regexp::Common 'number';
$_ = '.';
/^$RE{num}{real}$/ and print "\"$_\" is a number.\n"
Preston [mailto:[EMAIL PROTECTED]
Sent: Mon 7/12/2004 6:32 PM
To: [EMAIL PROTECTED]; 'Gunnar Hjalmarsson'
Cc: [EMAIL PROTECTED]
Subject: RE: Regex for numbers and text
Jeff,
What needs to be changed in /(
Jerry Preston wrote:
Jeff,
What needs to be changed in /(-?\d+\.?\d*)/ so that it also see number like
.59?
This is why I like to recommend Regexp::Common. But...
Here is an example from Jeffrey Friedl's, "Mastering Regular Expressions":
/-?([0-9]+(\.[0-9]*)?|\.[0-9]+)/
perlified:
/-?(?:\d+(?:\.\d*
Jerry Preston wrote:
Jeff,
What needs to be changed in /(-?\d+\.?\d*)/ so that it also see
number like .59?
Have you seen any of the Perl documentation sections that deals with
regular expressions? This one, for instance, for a quick overview:
http://www.perldoc.com/perl5.8.4/pod/perlrequick.
Jeff,
What needs to be changed in /(-?\d+\.?\d*)/ so that it also see number like
.59?
Thanks,
Jerry
-Original Message-
From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]
Sent: Sunday, July 11, 2004 9:20 PM
To: Gunnar Hjalmarsson
Cc: [EMAIL PROTECTED]
Subject: Re: Regex f
Jerry,
Jerry> What am I doing wrong?
Such an open question. I assume you mean what is wrong with your code. To
answer, it isn't doing what you want it to do :-)
Jerry> I am trying to setup a single regex
Jerry> to breakdown the following lines:
Jerry>
Jerry> Jerry2.74 4.5
On Jul 10, Jerry Preston said:
>Jerry 2.74 4.5 mon
>Mark -14-10.75 -10 new
>
> /(\w+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(\w+)/;
Have you considered just using split()?
my @fields = split;
# or
my ($name, $x, $y, $z, $whatever) = split;
--
On Jul 11, Gunnar Hjalmarsson said:
>Jerry Preston wrote:
>> I am trying to setup a single regex to breakdown the following lines:
>>
>> Jerry2.74 4.5 mon
>> Mark -14-10.75 -10 new
>>
>> /(\w+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(\w+)/;
>
>You
Gunnar Hjalmarsson wrote:
Randal L. Schwartz wrote:
Gunnar Hjalmarsson writes:
/(\w+)(?:\s+$RE{num}{real}){3,3}\s+(\w+)/;
That's an alternative, but would it necessarily be better? To me,
using a module for such a trivial thing just creates another
level of abstraction without actually making it
Randal L. Schwartz wrote:
Gunnar Hjalmarsson writes:
/(\w+)(?:\s+$RE{num}{real}){3,3}\s+(\w+)/;
That's an alternative, but would it necessarily be better? To me,
using a module for such a trivial thing just creates another
level of abstraction without actually making it easier.
Can we agree to dis
> "Gunnar" == Gunnar Hjalmarsson <[EMAIL PROTECTED]> writes:
>> /(\w+)(?:\s+$RE{num}{real}){3,3}\s+(\w+)/;
Gunnar> That's an alternative, but would it necessarily be better? To me,
Gunnar> using a module for such a trivial thing just creates another level of
Gunnar> abstraction without actual
Randy W. Sims wrote:
Gunnar Hjalmarsson wrote:
(-?\d+(?:\.\d+)?)
Better yet, use Regexp::Common:
use Regexp::Common qw(number);
/(\w+)(?:\s+$RE{num}{real}){3,3}\s+(\w+)/;
That's an alternative, but would it necessarily be better? To me,
using a module for such a trivial thing just creates anot
On 7/11/2004 1:07 AM, Gunnar Hjalmarsson wrote:
Jerry Preston wrote:
I am trying to setup a single regex to breakdown the following lines:
Jerry2.74 4.5mon
Mark-14-10.75 -10new
With
/(\w+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(\w+)/;
What am
Jerry Preston wrote:
I am trying to setup a single regex to breakdown the following lines:
Jerry 2.74 4.5 mon
Mark-14-10.75 -10 new
With
/(\w+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(\w+)/;
What am I doing wrong?
You are not showing us a complete pro
Jerry Preston wrote:
Hi!
I am trying to setup a single regex to breakdown the following lines:
Jerry 2.74 4.5 mon
Mark-14-10.75 -10 new
With
/(\w+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(\w+)/;
What am I doing wrong?
At first glance, the regex appear
Hi!
I am trying to setup a single regex to breakdown the following lines:
Jerry 2.74 4.5 mon
Mark-14-10.75 -10 new
With
/(\w+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(\w+)/;
What am I doing wrong?
Thanks,
Jerry
21 matches
Mail list logo