I am trying to test that a string is alphanumeric, can only contain _
and -
, and does not contain any double hyphens. So, I tested my regex phrase in the UI using the following format:
/^(?!.*--)[a-zA-Z0-9_-]+$/.test("myString"); //true
/^(?!.*--)[a-zA-Z0-9_-]+$/.test("my--String"); //false
However, when I try to implement this into my java back-end, it is failing the check.
Pattern pattern = Pattern.compile("(?!.*--)[a-zA-Z0-9_-]+");
Is the format for the pattern object incorrect?