1
egrep 'session\.[^0].*' i

will exclude

session.1.something 
session.2.something 
session.abc.something
session.def.something

How would you modify the regex to exclude not abc?

I would have thought that this would work, but it does not

egrep 'session\.^(abc).*' i   

I'd like to get back

session.1.something 
session.2.something 
session.def.something

1 Answer 1

2

Hope this will work fine

egrep 'session\.^(?!abc).*' i
3
  • 1
    Yup, just found that egrep 'sessions\.[^(|abc)].*' i works as well. Can you please explain what is the significance of ?! or | in my example? May 16, 2012 at 20:51
  • That's Lookahead and Lookbehind Assertions. See this: regular-expressions.info/lookaround.html.
    – Rahul
    May 16, 2012 at 20:55
  • With | you match multiple selection. Like /(hi|bye|hello)/
    – Rahul
    May 16, 2012 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.