On Jul 15, Kevin Pfeiffer said:
>Jeff 'japhy' Pinyan writes:
>[...]
>> Here's a working regex:
>>
>> s/(\d)(?=\d)/$1./g;
>
>[converts 1234 to 1.2.3.4]
>
>> The (?=\d) looks ahead for a digit, without actually consuming it.
>
>What does that mean? Does it say, "match a digit, but always check to
Jeff 'japhy' Pinyan writes:
[...]
> Here's a working regex:
>
> s/(\d)(?=\d)/$1./g;
[converts 1234 to 1.2.3.4]
> The (?=\d) looks ahead for a digit, without actually consuming it.
What does that mean? Does it say, "match a digit, but always check to see
that there is still at least one remai
Jess Balint wrote at Fri, 12 Jul 2002 20:03:58 +0200:
> You need '?';
>
> echo 123 | perl -pe 's/(\d?)(\d)/$1.$2/g'
>
That doesn't really work.
Look at
echo 123456 | perl -pe 's/(\d?)(\d)/$1.$2/g'
what prints
1.23.45.6
Cheerio,
Janek
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For ad
Ooh. I like that better than mine. :)
-Original Message-
From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 12, 2002 11:08 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: an error in a simple regexp
On Jul 12, Dusan Juhas said:
>I type
You need '?';
echo 123 | perl -pe 's/(\d?)(\d)/$1.$2/g'
[Jess]
-Original Message-
From: Dusan Juhas [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 12, 2002 12:17 PM
To: [EMAIL PROTECTED]
Subject: an error in a simple regexp
Hi,
I typed this simple cmd in the bash
7;,$_);
-Original Message-
From: Dusan Juhas [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 12, 2002 9:17 AM
To: [EMAIL PROTECTED]
Subject: an error in a simple regexp
Hi,
I typed this simple cmd in the bash:
echo 123 |perl -pe 's/(\d)(\d)/$1.$2/g'
and expected ouput like
1.2.3
but obtai
Dusan Juhas wrote at Fri, 12 Jul 2002 18:16:44 +0200:
> Hi,
> I typed this simple cmd in the bash:
> echo 123 |perl -pe 's/(\d)(\d)/$1.$2/g'
> and expected ouput like
> 1.2.3
> but obtained this one:
> 1.23
>
First your regexp finds
(1)(2) what is a matching.
So 1.2 is written.
Then 3 is left,
On Jul 12, Dusan Juhas said:
>I typed this simple cmd in the bash:
>echo 123 |perl -pe 's/(\d)(\d)/$1.$2/g'
>and expected ouput like
>1.2.3
>but obtained this one:
>1.23
The reason you don't get "1.2.3" is because by the time Perl has matched
"12", it can't match the "2" again.
Here's a working
Hi,
I typed this simple cmd in the bash:
echo 123 |perl -pe 's/(\d)(\d)/$1.$2/g'
and expected ouput like
1.2.3
but obtained this one:
1.23
What's wrong and how to write a regexp cmd which will
transfer a number to digits with dots in between?
eg: 1234 -> 1.2.3.4
Thanx
Regards,
Dusan
--
To uns
Mario Todorow <[EMAIL PROTECTED]> wrote:
>perl -ne ' print "$1\n" if /\s(\d+\.\d+\.\d+\.\d+)\s/ ' file
>
>is better.
Tnx, I'm already using something similar. Now there is another catch when
I have to deal with two IPs in a single line. I have to use regexp in LIST
context(i.e. @myips = $line =~
Matija Papec <[EMAIL PROTECTED]> wrote:
>Array is a text file with lines as its elements. It looks like:
>
>--txt file--
># ARIN: Aworldwidemall.com, VA - US
>ALL: 63.64.190.230
># ARIN: Aworldwidemall.com, VA - US
>ALL: 67.64.190.230
>.
>.
>.
>.
># ARIN: Aworldwidemall.com, VA - US
>ALL: 1
perl -ne ' print "$1\n" if /\s(\d+\.\d+\.\d+\.\d+)\s/ ' file
is better.
Try this one line command
perl -ne ' print "$1\n" if /\s(\S+\.\S+\.\S+\.\S+)\s/' file
Cordially
Mario
John Edwards <[EMAIL PROTECTED]> wrote:
>Here's a solution I sent to the group earlier...
tnx, but I used simpler regexp since IP numbers which I use are already
verified as valid.
>For the array thing, have you considered using a hash instead?? How do you
>know where to insert the data in the ar
source...
John
-Original Message-
From: George S Pereira [mailto:[EMAIL PROTECTED]]
Sent: 04 July 2001 11:46
To: John Edwards
Cc: 'Matija Papec'; Perl Beginners (E-mail)
Subject: Re: simple regexp
A simpler solution of checking for an IP address would be :
#! /opt/bin/perl -w
my($str)
A simpler solution of checking for an IP address would be :
#! /opt/bin/perl -w
my($str) = 'This is a string with 192.19.2.13 in it';
while ($str =~ m/(\d+\.\d+\.\d+\.\d+)/g)
{
if (defined $1)
{
print "IP address is $1\n";
}
}
This just prints the IP address if there is one.
Ge
Here's a solution I sent to the group earlier...
For the array thing, have you considered using a hash instead?? How do you
know where to insert the data in the array? Is it needed after another
value, or at a certain element??
John
-Original Message-
From: John Edwards
Sent: 14 June 2
This is pretty beginners question, how can I extract IP number from $s?
$s = "ALL: 172.184.70.165 # PORT: 59"
Pattern have to match four numbers separated by "."
Besides I have some array and need to insert some values into it(somewhere
in the middle). "perldoc -f splice" says that it only doe
18 matches
Mail list logo