-1

I am new to java regex. Can you please give a matching pattern for the following requirement. Example: "Apple" or "Google" should not be matched since there are consecutive characters in them. But, words like "Hard2Crack" or "Sometimes" should match.

Your help is appreciated.

2 Answers2

2

You can use this regex:

^(?:(.)(?!\1))*$

Demo

anubhava
  • 664,788
  • 59
  • 469
  • 547
0
(?!.*?([a-z])\1)^.*$

You can try this.uses a negative looakahead.

See demo.

http://regex101.com/r/oC3nN4/13

vks
  • 63,206
  • 9
  • 78
  • 110