-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
  • 713,503
  • 59
  • 514
  • 593
0
(?!.*?([a-z])\1)^.*$

You can try this.uses a negative looakahead.

See demo.

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

vks
  • 65,133
  • 10
  • 87
  • 119