[英]Regex for strings containing at least 4 unique printable ASCII characters excluding few special characters
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.我想出了下面的正则表达式,它匹配至少有 4 个唯一字符的字符串,以及所有可打印的 ASCII 字符,不包括空格。
^([!-~]+)((?!\1)[!-~]+)((?!\1|\2)[!-~]+)((?!\1|\2|\3)[!-~]+)$
How do I modify it to exclude comma (,), colon (:), equals sign (=)?如何修改它以排除逗号 (,)、冒号 (:)、等号 (=)?
In Java you can make use of Character Class Subtraction .在 Java 中,您可以使用Character Class Subtraction 。
The range can look like [!-~&&[^,:=]]
范围看起来像
[!-~&&[^,:=]]
^([!-~&&[^,:=]]+)((?!\1)[!-~&&[^,:=]]+)((?!\1|\2)[!-~&&[^,:=]]+)((?!\1|\2|\3)[!-~&&[^,:=]]+)$
In Java:在 Java 中:
String regex = "^([!-~&&[^,:=]]+)((?!\\1)[!-~&&[^,:=]]+)((?!\\1|\\2)[!-~&&[^,:=]]+)((?!\\1|\\2|\\3)[!-~&&[^,:=]]+)$";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.