0

I need to make a regex which will reject string with any given character in set next to each other

". / - ( )"

For example:

123()123 - false
123--123 - false
124((123 - false
123(123)123-12-12 - true

This is what i have done so far:

(?:([\/().-])(?!.*\1))
Stefan van den Akker
  • 6,661
  • 7
  • 48
  • 63
user1075940
  • 1,086
  • 2
  • 22
  • 46

3 Answers3

1
^((?![\/().-]{2}).)*$

This simply negates the regex [\/().-]{2} which matches if two of your characters are next to each other.

See this answer for further explanation.

Live demo

mousetail
  • 7,009
  • 4
  • 25
  • 45
halex
  • 16,253
  • 5
  • 58
  • 67
1

You can use :

(^(?:(?![.\/()-]{2}).)*$)

DEMO

Explanation :

enter image description here

Sujith PS
  • 4,776
  • 3
  • 34
  • 61
0

Maybe it is easier to do it other way around, match strings you don't want to allow.

if match [.\/()-]{2}
   not allowed
else
   allowed
end
Mattias Wadman
  • 11,172
  • 2
  • 42
  • 57