Re: help about regex matching
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Tue, 29 Nov 2005 00:50:24 -0800
Jeff Pang wrote:
> hi,list,
Hello,
> I have a file looking as below:
>
> 356.5
> 192.168.2.20
>
> [snip]
>
> 612
> 192.168.2.31
>
> ...
>
>
> I want to get this result:
>
> 356.5 192.168.2.20
> 283.3 192.168.2.21
> 261.9 192.168.2.22
> ...
>
>
> and,I write this regex for matching:
>
> {
> local $/="";
> while (<FILE>)
> {
> next unless /^(.+?)$(?=.*(\d+\.\d+\.\d+\.\d+))/sm;
> print $1,"\t",$2,"\n";
> }
> }
>
> but it can't work correctly.
> So,I want to know how to adjust this regex?Thanks.
Probably something like this:
{
local $/ = '';
while ( <FILE> )
{
next unless /(\S+)\s+(\d+\.\d+\.\d+\.\d+)/;
print "$1\t$2\n";
}
}
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
- help about regex matching
- Prev by Date: Re: Matching a Scalar Variable
- 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
|
|