Reputation: 9996
I am working on an application, in which input strings must have following properties:
I came up with below regex, which matches strings with at least 4 unique chars, and all printable ASCII chars excluding space.
^([!-~]+)((?!\1)[!-~]+)((?!\1|\2)[!-~]+)((?!\1|\2|\3)[!-~]+)$
How do I modify it to exclude comma (,), colon (:), equals sign (=)?
Upvotes: 0
Views: 78
Reputation: 163517
In Java you can make use of Character Class Subtraction.
The range can look like [!-~&&[^,:=]]
^([!-~&&[^,:=]]+)((?!\1)[!-~&&[^,:=]]+)((?!\1|\2)[!-~&&[^,:=]]+)((?!\1|\2|\3)[!-~&&[^,:=]]+)$
In Java:
String regex = "^([!-~&&[^,:=]]+)((?!\\1)[!-~&&[^,:=]]+)((?!\\1|\\2)[!-~&&[^,:=]]+)((?!\\1|\\2|\\3)[!-~&&[^,:=]]+)$";
Upvotes: 2