I have been banging my head against this for some time now:
I want to capture all [a-z]+[0-9]?
character sequences excluding strings such as sin|cos|tan
etc.
So having done my regex homework the following regex should work:
(?:(?!(sin|cos|tan)))\b[a-z]+[0-9]?
As you see I am using negative lookahead along with alternation - the \b
after the non-capturing group closing parenthesis is critical to avoid matching the in
of sin
etc. The regex makes sense and as a matter of fact I have tried it with RegexBuddy and Java as the target implementation and get the wanted result but it doesn't work using Java Matcher and Pattern objects!
Any thoughts?
cheers
?:
when you use?!
. – Briarwood?:
- zero-width assertions are not captured by default. As far as the regex engine is concerned,(?:(?!(sin|cos|tan)))
is a complex way of saying(?!sin|cos|tan)
. – Denyse