-2

I want a java regular expression, that can be used to match this text:

variable(X).

The X can be any string, that only contains characters a-z,A-Z,0-9.

But the rules are, X != tab and X != foo.

Also the X cannot be empty string.

Also X must begin with a a-z character.

So far I have variable\([a-z]([a-zA-Z]|\d)*\), but I don't know how to write the not equals to part...

omega
  • 40,311
  • 81
  • 251
  • 474

1 Answers1

1

This regex should work for you:

^variable\s*\(((?!(?:foo|tab)\))[a-z][a-zA-Z0-9]*)\)

In Java:

^variable\\s*\\(((?!(?:foo|tab)\\))[a-z][a-zA-Z0-9]*)\\)

Live Demo: http://www.rubular.com/r/0TN8bmmQLS

anubhava
  • 761,203
  • 64
  • 569
  • 643