Re: Regex for numbers and text

2004-07-13 Thread Jeff 'japhy' Pinyan
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

Re: Regex for numbers and text

2004-07-13 Thread Gunnar Hjalmarsson
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

Re: Regex for numbers and text

2004-07-13 Thread Gunnar Hjalmarsson
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

Re: Regex for numbers and text

2004-07-13 Thread Jeff 'japhy' Pinyan
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

Re: Regex for numbers and text

2004-07-13 Thread Randy W. Sims
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

Re: Regex for numbers and text

2004-07-13 Thread Gunnar Hjalmarsson
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"

RE: Regex for numbers and text

2004-07-12 Thread Tim Johnson
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 /(

Re: Regex for numbers and text

2004-07-12 Thread Randy W. Sims
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*

Re: Regex for numbers and text

2004-07-12 Thread Gunnar Hjalmarsson
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.

RE: Regex for numbers and text

2004-07-12 Thread Jerry Preston
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

Re: Regex for numbers and text (ANS)

2004-07-12 Thread Adam
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

Re: Regex for numbers and text

2004-07-11 Thread Jeff 'japhy' Pinyan
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; --

Re: Regex for numbers and text

2004-07-11 Thread Jeff 'japhy' Pinyan
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

Module reuse (was: Re: Regex for numbers and text)

2004-07-11 Thread Randy W. Sims
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

Re: Regex for numbers and text

2004-07-11 Thread Gunnar Hjalmarsson
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

Re: Regex for numbers and text

2004-07-11 Thread Randal L. Schwartz
> "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

Re: Regex for numbers and text

2004-07-11 Thread Gunnar Hjalmarsson
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

Re: Regex for numbers and text

2004-07-10 Thread Randy W. Sims
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

Re: Regex for numbers and text

2004-07-10 Thread Gunnar Hjalmarsson
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

Re: Regex for numbers and text

2004-07-10 Thread Andrew Gaffney
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