Reputation: 1125
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))
Upvotes: 0
Views: 66
Reputation: 16403
^((?![\/().-]{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.
Upvotes: 1
Reputation: 11425
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
Upvotes: 0