>>>> I'd like to snag all the whitespace padded numbers in $_ into an array,
>>>> e.g.
>>>> in the following:
>>>> 
>>>> 1 "M_fx,-3,+2.p2" -31.4e-1 4.
>>>> 
>>>> I'd like to pick up only the 1, -31.4e-1, and 4.
>>>> 
>>>> I've tried:
>>>> 
>>>> $ss = qr/(^|\s)[+-]?[0-9]+\.?[0-9]*([eE][+-]?[0-9]+\.?[0-9]*)?($|\s)/;
>>>> @list = m/$ss/g;
>>>> 
>>>> ... but it slurps up the leading whitespace if it's there, and misses every
>>>> other number, amid other problems.  I'd love to use \b, but it doesn't work
>>>> if there are "-" or "+" at the leading edge.
>>>> 
>>>> Any good ideas on how to do this?
>>> 
>>> This should work:
>>> 
>>> /(?:^|\s)((?:[+-]?)(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee](?:[+-]?\d+))?)/
>> 
>> 
>> 
>> This is the right direction, but it grabs numbers that look like this:
>> 
>> 1111xxxx
> 
> Well, it grabs the 1111.
> 
>> 
>> Is it possible to keep from grabbing those?
> 
> Add a look-ahead assertion like this at the very end of the regex:
> 
>     (?=\s|$)


Excellent, it seems to work now.  Thank you!

- Bryan




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to