RE: Simple regex question

2009-05-19 Thread Ajay Kumar

Hi Alexander
Or you can use this
($temp=~ m/([A-Za-z0-9]{5})\.([0-9]{1,2})[+-]([0-9]{1,4})\.([0-9]{1,4})/);
This is more compact and accurate

Thanks and regards
Ajay


-Original Message-
From: Alexander Koenig [mailto:alexander.koe...@mpi.nl]
Sent: Tuesday, May 19, 2009 7:25 PM
To: beginners@perl.org
Subject: Re: Simple regex question

You wrote on 05/19/2009 03:18 PM:
> Simple question for the regEXperts out there...
>
> I have a string that is always in the format:  a.nn+x.y
>
> a is always 5 chars
> n can be 1 or 2 digits
> x can be +/- (with sign), 1-4 digits
> y is always positive (no sign), 1-4 digits

The best I can come up with on the fly would be something like this:

---

#!/usr/bin/perl

use strict;
use warnings;

my @test = ('A123C.11+002.001','FC32G.2-1.0','12B15.01+2145.15');

foreach my $item (@test)
{
print "$item\n\n";
($a,$n,$x,$y)) = $item =~ /(.{5})\.(\d\d?)[-+](\d{1,4})\.(\d{1,4})/;
my ($lengthx, $lengthy) = (length $x, length $y);
print "a = $a, n = $n, x = $x, y = $y, length x = $lengthx, length y =
$lengthy\n";
}
---

But the real experts can probably compress it much more still.

hth
Alex

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Simple regex question

2009-05-19 Thread John W. Krahn

Dan Fish wrote:

Simple question for the regEXperts out there...

I have a string that is always in the format:  a.nn+x.y 

a is always 5 chars 


[a-zA-Z0-9]{5}



n can be 1 or 2 digits


[0-9]{1,2}



x can be +/- (with sign), 1-4 digits


[-+][0-9]{1,4}



y is always positive (no sign), 1-4 digits


[0-9]{1,4}



Some examples:
A123C.11+002.001
FC32G.2-1.0
12B15.01+2145.15

I need all 4 pieces and the length of x & y. The following works:

my $id= "A123C.11+002.001";

my @tmp = split(/[\.+-]/,$id);
my $part = $tmp[0];
my $unit = $tmp[1];
my $x = $tmp[2];
my $y = $tmp[3];
my $xlen = length $tmp[2];
my $ylen = length $tmp[3];

but in my quest for understanding regex, I'm always looking for more elegant
(obfuscated :-) code... 
Anybody have a good one-liner for this?


my ($part,$unit,$x,$y,$xlen,$ylen) = /* Some obfuscated code here.. */


my ( $part, $unit, $x, $y, $xlen, $ylen ) = (
$id =~ m{
\A
( [a-zA-Z0-9]{5} )
\.
( [0-9]{1,2} )
[-+]
( [0-9]{1,4} )
\.
( [0-9]{1,4} )
\z
}x,
length $3,
length $4,
);




John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Simple regex question

2009-05-19 Thread John W. Krahn

Chas. Owens wrote:

On Tue, May 19, 2009 at 09:55, Alexander Koenig  wrote:
snip

($a,$n,$x,$y)) = $item =~ /(.{5})\.(\d\d?)[-+](\d{1,4})\.(\d{1,4})/;

snip

As of Perl 5.8 \d no longer matches [0-9].

  ^

As of Perl 5.8 \d no longer matches only [0-9].



It now matches any UNICODE character that has the digit property.



John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Simple regex question

2009-05-19 Thread John W. Krahn

Dan Fish wrote:

Simple question for the regEXperts out there...

I have a string that is always in the format:  a.nn+x.y 

a is always 5 chars 


[a-zA-Z0-9]{5}



n can be 1 or 2 digits


[0-9]{1,2}



x can be +/- (with sign), 1-4 digits


[-+][0-9]{1,4}



y is always positive (no sign), 1-4 digits


[0-9]{1,4}



Some examples:
A123C.11+002.001
FC32G.2-1.0
12B15.01+2145.15

I need all 4 pieces and the length of x & y. The following works:

my $id= "A123C.11+002.001";

my @tmp = split(/[\.+-]/,$id);
my $part = $tmp[0];
my $unit = $tmp[1];
my $x = $tmp[2];
my $y = $tmp[3];
my $xlen = length $tmp[2];
my $ylen = length $tmp[3];

but in my quest for understanding regex, I'm always looking for more elegant
(obfuscated :-) code... 
Anybody have a good one-liner for this?


my ($part,$unit,$x,$y,$xlen,$ylen) = /* Some obfuscated code here.. */


my ( $part, $unit, $x, $y, $xlen, $ylen ) = (
$id =~ m{
\A
( [a-zA-Z0-9]{5} )
\.
( [0-9]{1,2} )
[-+]
( [0-9]{1,4} )
\.
( [0-9]{1,4} )
\z
}x,
length $3,
length $4,
);



John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Simple regex question

2009-05-19 Thread Chas. Owens
On Tue, May 19, 2009 at 10:21, Alexander Koenig  wrote:
> Chas. Owens wrote on 05/19/2009 04:02 PM:
>
>>> ($a,$n,$x,$y)) = $item =~ /(.{5})\.(\d\d?)[-+](\d{1,4})\.(\d{1,4})/;
>> snip
>>
>> As of Perl 5.8 \d no longer matches [0-9].  It now matches any UNICODE
>> character that has the digit property.  This includes characters such
>> as "\x{1815}" (MONGOLIAN DIGIT FIVE).  You must use [0-9] if you mean
>> [0-9] or use the bytes pragma[1] to return the old meaning of \d (but
>> this breaks all UNICODE processing in the scope you declare it).
>
> Oh, I didn't know that. Thanks for pointing that out.
>
> But in most scenarios \d will still work, right? I mean, how often do
> you actually encounter the Mongolian Digit Five in real life data?

It isn't just "\x{1815}", it is any UNICODE character with the digit
property.  That includes things like "\x{FF15}" (FULLWIDTH DIGIT FIVE)
which look just like a normal number 5, but you can't do math with it.
 If you mean [0-9] you should say [0-9], if you mean something that
looks vaguely like a number to somebody you should say \d.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Simple regex question

2009-05-19 Thread Alexander Koenig
Chas. Owens wrote on 05/19/2009 04:02 PM:

>> ($a,$n,$x,$y)) = $item =~ /(.{5})\.(\d\d?)[-+](\d{1,4})\.(\d{1,4})/;
> snip
> 
> As of Perl 5.8 \d no longer matches [0-9].  It now matches any UNICODE
> character that has the digit property.  This includes characters such
> as "\x{1815}" (MONGOLIAN DIGIT FIVE).  You must use [0-9] if you mean
> [0-9] or use the bytes pragma[1] to return the old meaning of \d (but
> this breaks all UNICODE processing in the scope you declare it).

Oh, I didn't know that. Thanks for pointing that out.

But in most scenarios \d will still work, right? I mean, how often do
you actually encounter the Mongolian Digit Five in real life data?

bye
Alex

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Simple regex question

2009-05-19 Thread Dan Fish
> > Simple question for the regEXperts out there...
> >
> > I have a string that is always in the format:  a.nn+x.y
> >
> > a is always 5 chars
> > n can be 1 or 2 digits
> > x can be +/- (with sign), 1-4 digits
> > y is always positive (no sign), 1-4 digits
> snip
> 
> What do you mean by chars?  Is any character valid or are only
> printable characters valid, or only printable ASCII characters, or
> a-z, A-Z, and 0-9?
> (snip)

Agreed, should have been clearer on this... a is alphanum, a-z,A-Z,0-9

Thanks Chas


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Simple regex question

2009-05-19 Thread Andrew Curry
A crude one

($part,$unit,$x,$y,$xlen,$ylen) = ($1,$2,$3,length($4),length($5))
if ($string =~ /(^\S{5})\.(\d{2})([+-])(\d+)\.(\d+)$/);



-Original Message-
From: Dan Fish [mailto:d...@ninemoons.com] 
Sent: 19 May 2009 14:18
To: beginners@perl.org
Subject: Simple regex question

Simple question for the regEXperts out there...

I have a string that is always in the format:  a.nn+x.y 

a is always 5 chars 
n can be 1 or 2 digits
x can be +/- (with sign), 1-4 digits
y is always positive (no sign), 1-4 digits


Some examples:
A123C.11+002.001
FC32G.2-1.0
12B15.01+2145.15

I need all 4 pieces and the length of x & y. The following works:

my $id= "A123C.11+002.001";

my @tmp = split(/[\.+-]/,$id);
my $part = $tmp[0];
my $unit = $tmp[1];
my $x = $tmp[2];
my $y = $tmp[3];
my $xlen = length $tmp[2];
my $ylen = length $tmp[3];

but in my quest for understanding regex, I'm always looking for more
elegant
(obfuscated :-) code... 
Anybody have a good one-liner for this?

my ($part,$unit,$x,$y,$xlen,$ylen) = /* Some obfuscated code here.. */


Thanks!
-Dan

---
d...@mapson.ninemoons.com
(To reply via email, remove 'reverse(nospam)' in address.  Spambots are
getting wy too smart nowadays...:-) 


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/



This email is from the Press Association.  For more information, see 
www.pressassociation.com.
This email may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this email is personal to the sender and may not 
reflect the opinion of the Press Association.
Any email reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Simple regex question

2009-05-19 Thread Chas. Owens
On Tue, May 19, 2009 at 09:55, Alexander Koenig  wrote:
snip
> ($a,$n,$x,$y)) = $item =~ /(.{5})\.(\d\d?)[-+](\d{1,4})\.(\d{1,4})/;
snip

As of Perl 5.8 \d no longer matches [0-9].  It now matches any UNICODE
character that has the digit property.  This includes characters such
as "\x{1815}" (MONGOLIAN DIGIT FIVE).  You must use [0-9] if you mean
[0-9] or use the bytes pragma[1] to return the old meaning of \d (but
this breaks all UNICODE processing in the scope you declare it).

1. http://perldoc.perl.org/bytes.html

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Simple regex question

2009-05-19 Thread Chas. Owens
On Tue, May 19, 2009 at 09:18, Dan Fish  wrote:
> Simple question for the regEXperts out there...
>
> I have a string that is always in the format:  a.nn+x.y
>
> a is always 5 chars
> n can be 1 or 2 digits
> x can be +/- (with sign), 1-4 digits
> y is always positive (no sign), 1-4 digits
snip

What do you mean by chars?  Is any character valid or are only
printable characters valid, or only printable ASCII characters, or
a-z, A-Z, and 0-9?

a is (.{5}) or ([[:print:]]{5}) or ([\x{20}-\x{7e}]{5}) or ([a-zA-Z0-9]{5})
. is [.]
n is ([0-9]{1,2})
x is ([+-][0-9]{1,4})
. is [.]
y is ([0-9]{1,4})


>
>
> Some examples:
>        A123C.11+002.001
>        FC32G.2-1.0
>        12B15.01+2145.15
>
> I need all 4 pieces and the length of x & y. The following works:
>
> my $id= "A123C.11+002.001";
>
> my @tmp = split(/[\.+-]/,$id);
> my $part = $tmp[0];
> my $unit = $tmp[1];
> my $x = $tmp[2];
> my $y = $tmp[3];
> my $xlen = length $tmp[2];
> my $ylen = length $tmp[3];
snip

my ($part, $unit, $x, $y) = / (.{5}) [.] ([0-9]{1,2}) ([+-][0-9]{1,4})
[.] ([0-9]{1,4}) /x
my ($xlen, $ylen) = map length, $x, $y;

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Simple regex question

2009-05-19 Thread Alexander Koenig
You wrote on 05/19/2009 03:18 PM:
> Simple question for the regEXperts out there...
> 
> I have a string that is always in the format:  a.nn+x.y 
> 
> a is always 5 chars 
> n can be 1 or 2 digits
> x can be +/- (with sign), 1-4 digits
> y is always positive (no sign), 1-4 digits

The best I can come up with on the fly would be something like this:

---

#!/usr/bin/perl

use strict;
use warnings;

my @test = ('A123C.11+002.001','FC32G.2-1.0','12B15.01+2145.15');

foreach my $item (@test)
{
print "$item\n\n";
($a,$n,$x,$y)) = $item =~ /(.{5})\.(\d\d?)[-+](\d{1,4})\.(\d{1,4})/;
my ($lengthx, $lengthy) = (length $x, length $y);
print "a = $a, n = $n, x = $x, y = $y, length x = $lengthx, length y =  
$lengthy\n";
}
---

But the real experts can probably compress it much more still.

hth
Alex

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Simple RegEx Question

2002-09-11 Thread Timothy Johnson


No.  the $ anchor assumes that you might have a "\n" at the end of your
string and doesn't include it in the match, so "zzqg" and "zzqg\n";  would
both match.

-Original Message-
From: RTO RTO [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 11, 2002 8:26 AM
To: Bob Showalter; [EMAIL PROTECTED]
Subject: RE: Simple RegEx Question


Thanks Nikola and Bob.

Would "anchoring with \z" tantamount to having a
trailing "$"? In other words, are the following
expressions one and the same?

 /^[0-9a-fA-F]+\z/
 /^[0-9a-fA-F]+$/



__
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Simple RegEx Question

2002-09-11 Thread RTO RTO

Thanks Nikola and Bob.

Would "anchoring with \z" tantamount to having a
trailing "$"? In other words, are the following
expressions one and the same?

 /^[0-9a-fA-F]+\z/
 /^[0-9a-fA-F]+$/



__
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Simple RegEx Question

2002-09-11 Thread Nikola Janceski

# should be
  if(/^[0-9A-F]+\z/i){
print("$_ is a hexadecimal number!\n");
  }else{
print("$_ is not a hexadecimal number!\n"); ## even blanks
  }

-Original Message-
From: RTO RTO [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 11, 2002 11:20 AM
To: Nikola Janceski; [EMAIL PROTECTED]
Subject: RE: Simple RegEx Question


use strict;
while(){
  chomp;
  if(/[^0-9a-fA-F]+/){
 print("$_ is not a hexadecimal number!\n");
  }else{
print("$_ is a hexadecimal number!\n");
  }
}
__DATA__
f4dxf
ffaa99

gxad
2832
2842da

--- Nikola Janceski <[EMAIL PROTECTED]>
wrote:
> give us a snippet of your code. you made a mistake
> somewhere.
> and give us examples of what the variables contain.
> 


__
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Simple RegEx Question

2002-09-11 Thread RTO RTO

use strict;
while(){
  chomp;
  if(/[^0-9a-fA-F]+/){
 print("$_ is not a hexadecimal number!\n");
  }else{
print("$_ is a hexadecimal number!\n");
  }
}
__DATA__
f4dxf
ffaa99

gxad
2832
2842da

--- Nikola Janceski <[EMAIL PROTECTED]>
wrote:
> give us a snippet of your code. you made a mistake
> somewhere.
> and give us examples of what the variables contain.
> 


__
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Simple RegEx Question

2002-09-11 Thread Bob Showalter

> -Original Message-
> From: RTO RTO [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 11, 2002 11:00 AM
> To: [EMAIL PROTECTED]
> Subject: Simple RegEx Question
> 
> 
> Here is a RegEx that I am using to check if the given
> string is Hexadecimal or not.
> 
> /[^0-9a-fA-F]+/   #if this evals to true string is NOT
> hex

This regex is true if there is a sequence of one or more characters that are
not valid hex digits.

> 
> I am having a trailing "+" to make sure at least one
> permissible character is present. 

The + is not necessary. If there's one non-hex digit, that's enough to
invalidate the string, right?

> Yet, it matches an
> empty string as a hex string.
> 
> a) What am I missing? 
> b) Why is an empty string being matched?

Your regex only matches if theres a non-hex digit. An empty string doesn't
have any hex digits, so it doesn't match.

Perhaps you should turn it around:

   /^[0-9a-fA-F]+\z/

This matches only if the entire string consists of a sequence of one or more
valid hex digits. This will not treat an empty string as valid. The ^
(before the square bracket) anchors to the beginning of the string, while \z
anchors to the end of the string.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Simple RegEx Question

2002-09-11 Thread Nikola Janceski

give us a snippet of your code. you made a mistake somewhere.
and give us examples of what the variables contain.

-Original Message-
From: RTO RTO [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 11, 2002 11:09 AM
To: Nikola Janceski; [EMAIL PROTECTED]
Subject: RE: Simple RegEx Question


I am afraid, your suggestion is even breaking for
already working ones! i.e., it says HEXADECIMAL NUMBER
for an invalid string like "f4dx" and also says
HEXADECIMAL NUMBER for invalid empty strings.

The one I had posited,without the leading "^" and "$"
matched for all the cases correctly, except for empty
strings. Hence the question.

Thanks,
Rex

--- Nikola Janceski <[EMAIL PROTECTED]>
wrote:
> see below
> 
> /^[^0-9a-fA-F]+$/   #if this evals to true string is
> NOT
> 
> ## start of string ^ and end of string $
> 



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Simple RegEx Question

2002-09-11 Thread RTO RTO

I am afraid, your suggestion is even breaking for
already working ones! i.e., it says HEXADECIMAL NUMBER
for an invalid string like "f4dx" and also says
HEXADECIMAL NUMBER for invalid empty strings.

The one I had posited,without the leading "^" and "$"
matched for all the cases correctly, except for empty
strings. Hence the question.

Thanks,
Rex

--- Nikola Janceski <[EMAIL PROTECTED]>
wrote:
> see below
> 
> /^[^0-9a-fA-F]+$/   #if this evals to true string is
> NOT
> 
> ## start of string ^ and end of string $
> 
> -Original Message-
> From: RTO RTO [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 11, 2002 11:00 AM
> To: [EMAIL PROTECTED]
> Subject: Simple RegEx Question
> 
> 
> Here is a RegEx that I am using to check if the
> given
> string is Hexadecimal or not.
> 
> /[^0-9a-fA-F]+/   #if this evals to true string is
> NOT
> hex
> 
> I am having a trailing "+" to make sure at least one
> permissible character is present. Yet, it matches an
> empty string as a hex string.
> 
> a) What am I missing? 
> b) Why is an empty string being matched?
> 
> 
> 
> Thanks,
> Rex
> 
> 
> __
> Yahoo! - We Remember
> 9-11: A tribute to the more than 3,000 lives lost
> http://dir.remember.yahoo.com/tribute
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
>

> 
> The views and opinions expressed in this email
> message are the sender's
> own, and do not necessarily represent the views and
> opinions of Summit
> Systems Inc.
> 


__
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Simple RegEx Question

2002-09-11 Thread Nikola Janceski

see below

/^[^0-9a-fA-F]+$/   #if this evals to true string is NOT

## start of string ^ and end of string $

-Original Message-
From: RTO RTO [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 11, 2002 11:00 AM
To: [EMAIL PROTECTED]
Subject: Simple RegEx Question


Here is a RegEx that I am using to check if the given
string is Hexadecimal or not.

/[^0-9a-fA-F]+/   #if this evals to true string is NOT
hex

I am having a trailing "+" to make sure at least one
permissible character is present. Yet, it matches an
empty string as a hex string.

a) What am I missing? 
b) Why is an empty string being matched?



Thanks,
Rex


__
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Simple regex question

2002-03-30 Thread bob ackerman

Ah... i see.
in scalar context, it returns false until left is true. then returns true 
until right is true.
just what we want. very handy.
thanks.

On Saturday, March 30, 2002, at 11:48  AM, Jenda Krynicky wrote:

> From: bob ackerman <[EMAIL PROTECTED]>
>> sorry. still in dark.
>> what exactly does '/START_KEYWORD/.../END_KEYWORD/' mean?
>> I see a regex ->  /START_KEYWORD/
>> an ellipsis -> ...
>> and a regex -> /END_KEYWORD/
>> you are saying the whole thing means something, but I don't understand
>> what. you say 'the elipsis returns false' what does that mean? what is
>> it able to match? and why?
>
> I see ... here is the problem.
>
> The ... and .. operators are explained in the perlop manpage
>
> Search for "Range Operators"
>
> Jenda
>
> === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
> There is a reason for living. There must be. I've seen it somewhere.
> It's just that in the mess on my table ... and in my brain
> I can't find it.
>   --- me
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Simple regex question

2002-03-30 Thread Jenda Krynicky

From:   bob ackerman <[EMAIL PROTECTED]>
> sorry. still in dark.
> what exactly does '/START_KEYWORD/.../END_KEYWORD/' mean?
> I see a regex ->  /START_KEYWORD/
> an ellipsis -> ...
> and a regex -> /END_KEYWORD/
> you are saying the whole thing means something, but I don't understand
> what. you say 'the elipsis returns false' what does that mean? what is
> it able to match? and why?

I see ... here is the problem.

The ... and .. operators are explained in the perlop manpage

Search for "Range Operators"

Jenda

=== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
--- me

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Simple regex question

2002-03-30 Thread bob ackerman

sorry. still in dark.
what exactly does '/START_KEYWORD/.../END_KEYWORD/' mean?
I see a regex ->  /START_KEYWORD/
an ellipsis -> ...
and a regex -> /END_KEYWORD/
you are saying the whole thing means something, but I don't understand 
what.
you say 'the elipsis returns false'
what does that mean? what is it able to match? and why?

On Saturday, March 30, 2002, at 10:23  AM, Jenda Krynicky wrote:

> From: bob ackerman <[EMAIL PROTECTED]>
>
>> i don't understand your answer. how will that match anything?
>> the first line matches the whole block ok, but then the match is
>> dropped by the '!' phrases since they are in the text. also, where is
>> documented the ellipsis in a grep? also, using two regexes on either
>> side of the ellipsis?
>
> I am not using two regexps on one site of the ellipsis.
>
> If I add braces into the code you'll get this:
>
>  grep { ( /START_KEYWORD/.../END_KEYWORD/ )
>   and ( !/START_KEYWORD/ )
>   and ( !/END_KEYWORD/} )
>
> Let's "interpret" the code in mind.
> We have
>
>   @data = ( "some header",
>   "some more unimportant stuff",
>   "START_KEYWORD",
>   "here's the text we want",
>   "and here some more",
>   "END_KEYWORD",
>   "and again some boring stuff"
>   );
>
>
>   @filtered = grep { ( /START_KEYWORD/.../END_KEYWORD/ )
>   and ( !/START_KEYWORD/ )
>   and ( !/END_KEYWORD/ ) } @data;
>
> So first Perl processes the first item ("some header") : the elipsis
> returns false, the other conditions are not even tried, item is not
> accepted.
>
> Second item ("some more unimportant stuff") : again the same,
> ellipsis is false => item is not accepted.
>
> Third item ("START_KEYWORD") : ellipsis matches, returns true
> and switches to the second state (that is it'll return true until it
> matches the END_KEYWORD), but the second condition returns
> false so the item is not accepted.
>
> Fourth item ("here's the text we want") : the item doesn't match the
> "ending condition" of the elipsis so the ellipsis still returns true, the
> other two conditions also return true (keep in mind that the regexps
> are negated!) => item is accepted.
>
> Fifth item : same as fourth
>
> Sixth item ("END_KEYWORD") : the "end condition" of the ellipsis
> matches, ellipis returns true but switches to the first (false) state,
> the second condition returns true, but the third condition returns
> false => item is not accepted.
>
> 
>
> Jenda
>
>
> === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
> There is a reason for living. There must be. I've seen it somewhere.
> It's just that in the mess on my table ... and in my brain
> I can't find it.
>   --- me
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>



Re: Simple regex question

2002-03-30 Thread Jenda Krynicky

From:   bob ackerman <[EMAIL PROTECTED]>

> i don't understand your answer. how will that match anything?
> the first line matches the whole block ok, but then the match is
> dropped by the '!' phrases since they are in the text. also, where is
> documented the ellipsis in a grep? also, using two regexes on either
> side of the ellipsis?

I am not using two regexps on one site of the ellipsis.

If I add braces into the code you'll get this:

 grep { ( /START_KEYWORD/.../END_KEYWORD/ )
and ( !/START_KEYWORD/ )
and ( !/END_KEYWORD/} )

Let's "interpret" the code in mind.
We have

@data = ( "some header",
"some more unimportant stuff",
"START_KEYWORD",
"here's the text we want",
"and here some more",
"END_KEYWORD",
"and again some boring stuff"
);


@filtered = grep { ( /START_KEYWORD/.../END_KEYWORD/ )
and ( !/START_KEYWORD/ )
and ( !/END_KEYWORD/ ) } @data;

So first Perl processes the first item ("some header") : the elipsis 
returns false, the other conditions are not even tried, item is not 
accepted.

Second item ("some more unimportant stuff") : again the same, 
ellipsis is false => item is not accepted.

Third item ("START_KEYWORD") : ellipsis matches, returns true 
and switches to the second state (that is it'll return true until it 
matches the END_KEYWORD), but the second condition returns 
false so the item is not accepted.

Fourth item ("here's the text we want") : the item doesn't match the 
"ending condition" of the elipsis so the ellipsis still returns true, the 
other two conditions also return true (keep in mind that the regexps 
are negated!) => item is accepted.

Fifth item : same as fourth

Sixth item ("END_KEYWORD") : the "end condition" of the ellipsis 
matches, ellipis returns true but switches to the first (false) state, 
the second condition returns true, but the third condition returns 
false => item is not accepted.



Jenda


=== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
--- me

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Simple regex question

2002-03-30 Thread bob ackerman

i don't understand your answer. how will that match anything?
the first line matches the whole block ok, but then the match is dropped 
by the '!' phrases
since they are in the text.
also, where is documented the ellipsis in a grep?
also, using two regexes on either side of the ellipsis?


On Saturday, March 30, 2002, at 05:04  AM, Jenda Krynicky wrote:

> From: Rob Lee <[EMAIL PROTECTED]>
>
>> I'm parsing a file with multiple Fortran-like blocks that look like:
>>  START_KEYWORD
>>   line 1
>>   line 2
>>  END_KEYWORD
>>
>> I want only the contents of each block, not the keywords.
>>
>> grep { /START_KEYWORD/.../END_KEYWORD/ }
>> returns the entire block - including the start and end keywords.
>>
>> Is there a slick way to only return the contents of the block (line 1
>> and line 2)?
>
> This is not realy a regex question. I think you want this:
>
> grep { /START_KEYWORD/.../END_KEYWORD/
>   and !/START_KEYWORD/
>   and !/END_KEYWORD/}
>
> But if the START_KEYWORD and END_KEYWORD is supposed
> to be the only thing on the lines then
>
> grep {chomp $_;
>   ($_ eq 'START_KEYWORD') ... ($_ eq 'END_KEYWORD')
>   and !($_ eq 'START_KEYWORD')
>   and !($_ eq 'END_KEYWORD')}
>
> would be quicker. (Notice the chomp() there. It might be
> unnecessary if the lines are already chomped, but keep in mind
> that it modifies the elements of the original array!)
>
> Jenda
>
> === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
> There is a reason for living. There must be. I've seen it somewhere.
> It's just that in the mess on my table ... and in my brain
> I can't find it.
>   --- me
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Simple regex question

2002-03-30 Thread Jenda Krynicky

From:   Rob Lee <[EMAIL PROTECTED]>

> I'm parsing a file with multiple Fortran-like blocks that look like:
>  START_KEYWORD
>   line 1
>   line 2
>  END_KEYWORD
> 
> I want only the contents of each block, not the keywords.
> 
> grep { /START_KEYWORD/.../END_KEYWORD/ } 
> returns the entire block - including the start and end keywords.
> 
> Is there a slick way to only return the contents of the block (line 1
> and line 2)?

This is not realy a regex question. I think you want this:

grep { /START_KEYWORD/.../END_KEYWORD/ 
and !/START_KEYWORD/
and !/END_KEYWORD/}

But if the START_KEYWORD and END_KEYWORD is supposed 
to be the only thing on the lines then 

grep {chomp $_;
($_ eq 'START_KEYWORD') ... ($_ eq 'END_KEYWORD')
and !($_ eq 'START_KEYWORD')
and !($_ eq 'END_KEYWORD')}

would be quicker. (Notice the chomp() there. It might be 
unnecessary if the lines are already chomped, but keep in mind 
that it modifies the elements of the original array!)

Jenda

=== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
--- me

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: simple regex question

2001-06-28 Thread John Edwards

Sorry. Ignore that. It's 5:30 and home time. What can I say.

Use this instead.

$dnvalue =~ /CN=(\w*)/;
$username = $1;
print $username

-Original Message-
From: John Edwards [mailto:[EMAIL PROTECTED]]
Sent: 28 June 2001 17:31
To: 'Mike Ring'; [EMAIL PROTECTED]
Subject: RE: simple regex question


There's no need to match past the CN=, then prepend the CN= back to the
string. Use the following

$dnvalue = "CN=foo,OU=bar,O=pah";

$dnvalue =~ /(CN=[A-Za-z0-9]*)/;
$username = $1;
print $username

This looks for CN= followed by any number of letters (upper or lowercase)
and numbers. If you don't mind matching on an underscore too (_) use the
following instead

$dnvalue =~ /(CN=\w*)/;


HTH

John

-Original Message-
From: Mike Ring [mailto:[EMAIL PROTECTED]]
Sent: 28 June 2001 17:17
To: [EMAIL PROTECTED]
Subject: simple regex question



Hello all.

I've learned a bit about regular expressions today. I have a string
formatted
like "CN=foo,OU=bar,O=pah" and I need to parse out "foo". I have created the
following code which does work:

$dnvalue =~ m/([^,]*)/;
$username = $1;
$username =~ s/(CN=)//;
print $username

However, I'd like to do the match/replace on a single line. Can anyone show
me
how to combine these statements into a more elegant regular expression?

Thanks,
Mike


--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.



--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.





RE: simple regex question

2001-06-28 Thread John Edwards

There's no need to match past the CN=, then prepend the CN= back to the
string. Use the following

$dnvalue = "CN=foo,OU=bar,O=pah";

$dnvalue =~ /(CN=[A-Za-z0-9]*)/;
$username = $1;
print $username

This looks for CN= followed by any number of letters (upper or lowercase)
and numbers. If you don't mind matching on an underscore too (_) use the
following instead

$dnvalue =~ /(CN=\w*)/;


HTH

John

-Original Message-
From: Mike Ring [mailto:[EMAIL PROTECTED]]
Sent: 28 June 2001 17:17
To: [EMAIL PROTECTED]
Subject: simple regex question



Hello all.

I've learned a bit about regular expressions today. I have a string
formatted
like "CN=foo,OU=bar,O=pah" and I need to parse out "foo". I have created the
following code which does work:

$dnvalue =~ m/([^,]*)/;
$username = $1;
$username =~ s/(CN=)//;
print $username

However, I'd like to do the match/replace on a single line. Can anyone show
me
how to combine these statements into a more elegant regular expression?

Thanks,
Mike


--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.





Re: simple regex question

2001-06-28 Thread Paul


--- Mike Ring <[EMAIL PROTECTED]> wrote:
> I've learned a bit about regular expressions today. I have a string
> formatted
> like "CN=foo,OU=bar,O=pah" and I need to parse out "foo". I have
> created the
> following code which does work:
> 
> $dnvalue =~ m/([^,]*)/;
> $username = $1;
> $username =~ s/(CN=)//;
> print $username
> 
> However, I'd like to do the match/replace on a single line. Can
> anyone show me
> how to combine these statements into a more elegant regular
> expression?

 my ($cn) = $dnvalue =~ /^CN=([^,]*),/;

The list context provided by the parens around $cn will make the match
return the value found. =o)

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/