-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
  • 761,203
  • 64
  • 569
  • 643
0
(?!.*?([a-z])\1)^.*$

You can try this.uses a negative looakahead.

See demo.

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

vks
  • 67,027
  • 10
  • 91
  • 124