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,242
  • 7
  • 43
  • 62
user1075940
  • 1,006
  • 2
  • 21
  • 43

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

Community
  • 1
  • 1
halex
  • 15,885
  • 5
  • 53
  • 65
1

You can use :

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

DEMO

Explanation :

enter image description here

Sujith PS
  • 4,606
  • 3
  • 30
  • 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
  • 10,882
  • 2
  • 41
  • 55