I am trying to create some regex that can test whether or not a string contains 2 forward slashes or two hypens for dates.
These would pass: 10/25/1984 2005/06/24 1882-03-14 05-29-1932
Here is the regex that is failing:
/[\-\/{2,}/g
CodePudding user response:
Either capture and check for backreference... (demo)
([-\/]).*?\1
Or simply use an alternation (demo)
-[^-]*-|\/[^\/]*\/
[^
...]
represents a negated character class.