Link to home
Start Free TrialLog in
Avatar of cjohnson300
cjohnson300

asked on

Match one string but not another

Can anyone help me to write a regular expression that matches "ecard", but not "scorecard" (without the double quotes)

Many thanks
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try "^ecard". ^ indicates the match must start with e.
Avatar of chiragypatil
chiragypatil

"[\ ]ecard[\ ]"

gives exactly "ecard"

I'm trying to make it work for following conditions (which currently dont work):
ecard at the begining or end of the line.
got it!!!

"\b[e][c][a][r][d]\b"

hope this is what u wanted
Avatar of cjohnson300

ASKER

I selected this answer because it was the first and it had the desired results
No problems as far as the solution works.
But i thaught my solution was more accurate.

I'm ok with any decision!
I have to agree ozo's answer is most elegant!