Re: help about regex matching
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Tue, 29 Nov 2005 01:52:09 -0800
Jeff Pang wrote:
> yes,John's code work well too.But I still don't know why this code
> can't run correctly:
>
> next unless /(\S+).*(\d+\.\d+\.\d+\.\d+)/s;
>
> When I run it,I get these results:
>
> 364 2.168.2.20
> 286.4 2.168.2.21
> 264.4 2.168.2.22
> 138 2.168.2.23
> 562.3 2.168.2.24
> 80.7 2.168.2.25
> 355 2.168.2.26
> 266.5 2.168.2.27
> 327 2.168.2.28
>
>
> somethings as '19' have lost.
That is because .* is greedy and will match everything to the end of the
string and then backtrack until (\d+\.\d+\.\d+\.\d+) matches which specifies
that the first \d+ only has to match at least one digit.
Since the two fields start and end with digits you could do this instead:
next unless /([\d.]+)\D+(\d+\.\d+\.\d+\.\d+)/;
John
--
use Perl;
program
fulfillment
.
- Follow-Ups:
- Re: help about regex matching
- From: Jeff Pang
- Re: help about regex matching
- References:
- help about regex matching
- From: Jeff Pang
- Re: help about regex matching
- From: John W. Krahn
- Re: help about regex matching
- From: Jeff Pang
- help about regex matching
- Prev by Date: RE: Error : Nested quantifiers before HERE mark in regex
- Next by Date: RE: help about regex matching
- Previous by thread: Re: help about regex matching
- Next by thread: Re: help about regex matching
- Index(es):
Relevant Pages
|
|