RE: EggExp Question

2005-01-14 Thread Gardner, Sam
Title: RE: EggExp Question





See below, from perlre:


So, your regex would be


$phone_book_entry=~m/^Smith.+(?!John)/;


(?!pattern)


A zero-width negative look-ahead assertion. For example /foo(?!bar)/ matches any occurrence of ``foo'' that isn't followed by ``bar''. Note however that look-ahead and look-behind are NOT the same thing. You cannot use this for look-behind. 

If you are looking for a ``bar'' that isn't preceded by a ``foo'', /(?!foo)bar/ will not do what you want. That's because the (?!foo) is just saying that the next thing cannot be ``foo''--and it's not, it's a ``bar'', so ``foobar'' will match. You would have to do something like /(?!foo)...bar/ for that. We say ``like'' because there's the case of your ``bar'' not having three characters before it. You could cover that this way: /(?:(?!foo)...|^.{0,2})bar/. Sometimes it's still easier just to say:

    if (/bar/ && $` !~ /foo$/)


Sam Gardner


GTO Application Development


Keefe, Bruyette & Woods, Inc.


212-887-6753






-Original Message-
From: Edwards, Mark (CXO) [mailto:[EMAIL PROTECTED]] 
Sent: Friday, January 14, 2005 12:16 PM
To: Perl-Win32-Users@listserv.ActiveState.com
Subject: EggExp Question



Is there a regular _expression_ to indicate a string you're looking for and one you're not looking for? 


Example: You want to find all the Smiths in a list but not Smith, John. So if you read each record from the list, the pseudo code would be something like:

$phone_book_entry=~m/^Smith.+?not(John)/



$phone_book_entry=~m/^Smith, [^J][^o][^h][^n]/ works but can be cumbersome for long strings. Also if you don't know that ", " is always between the last and first name (Smith Jr., John) and use .*?, it breaks.

Is there a real re that will do this?


Thanks


 
Mark Edwards 
HP Services 
Technical Solutions Group   
 <http://www.hp.com/>    Hewlett-Packard Company
    
CXO01-3/N13 
301 Rockrimmon Blvd. South  
Colorado Springs, CO 80919-2398     
Voice: (719) 592-5363       
Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>     


___
Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


EggExp Question

2005-01-14 Thread Edwards, Mark (CXO)
Is there a regular expression to indicate a string you're looking for
and one you're not looking for? 

Example: You want to find all the Smiths in a list but not Smith, John.
So if you read each record from the list, the pseudo code would be
something like:

$phone_book_entry=~m/^Smith.+?not(John)/


$phone_book_entry=~m/^Smith, [^J][^o][^h][^n]/ works but can be
cumbersome for long strings. Also if you don't know that ", " is always
between the last and first name (Smith Jr., John) and use .*?, it
breaks.

Is there a real re that will do this?

Thanks

 
Mark Edwards 
HP Services 
Technical Solutions Group   
 Hewlett-Packard Company

CXO01-3/N13 
301 Rockrimmon Blvd. South  
Colorado Springs, CO 80919-2398 
Voice: (719) 592-5363   
Email: [EMAIL PROTECTED]  

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs