CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
need some help on this 'simple' case

 



jerseyguy
New User

Oct 4, 2006, 8:07 AM

Post #1 of 4 (2608 views)
need some help on this 'simple' case Can't Post

hi, all

not sure it's a intermediate question, but i desperately need some help:

i need a regular expression to match a string which includes 'abc' except 'abc123' and 'abc456':

for example:

'abc' (match)

'abcdefg' (match)

'abc123' (not match)

'abc123456' (not match)

'abc456' (not match)

'abc456789' (not match)

'abcd123' (match)



thanks in advance


KevinR
Veteran


Oct 4, 2006, 10:02 AM

Post #2 of 4 (2607 views)
Re: [jerseyguy] need some help on this 'simple' case [In reply to] Can't Post

posting the same question in multiple forums is very obnoxious. If you want help with this question please post the code you have already been trying to use.
-------------------------------------------------


jerseyguy
New User

Oct 4, 2006, 10:57 AM

Post #3 of 4 (2605 views)
Re: [KevinR] need some help on this 'simple' case [In reply to] Can't Post

sorry KevinR, the situation is kind of urgent here.

here is my code:

$string1 = "abc123";
#$string1 = "msadc/msadcs.dll/navigatorobject";

if ($string1 =~ m/abc.*[^(123|456)]/) {
print "\yes\n";
}
else{
print "\nno\n";
}


it doesn't work, what i need is to match any string which includes 'abc' except 'abc123' and 'abc456'.


KevinR
Veteran


Oct 4, 2006, 1:57 PM

Post #4 of 4 (2603 views)
Re: [jerseyguy] need some help on this 'simple' case [In reply to] Can't Post

instead of:


Code
m/abc.*[^(123|456)]/


use:


Code
m/abc(?!123|456)/



The '?!' extension lets you specify what should not follow your pattern. You were using a negated character class which can maybe be used in some cases for this type of matching but the '?!' extension is better for what you are trying to do.

I hope I am not doing your school work for you. Frown
-------------------------------------------------


(This post was edited by KevinR on Oct 4, 2006, 1:57 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives