我正在尝试检查我的字符串是否包含以下任何字符\:*?”<>|/.
并且不以〜开头
我对正则表达式不太熟悉,可以真正使用一些帮助;)
答案 0 :(得分:0)
String input = "test";
boolean status = input.matches("(?=.*[\\:*?\"<>|/.])(?!^~).*");
System.out.println(status);
(?=.*[\\:*?\"<>|/.])
检查是否有任何一次提到的字符。
(?!^~)
表示~
不在开头。
.*
表示匹配整个字符串,因为matches()
方法对完整字符串执行匹配。
答案 1 :(得分:0)
鉴于你确切的字符\:*?”<>|/.
这应该工作
# "^(?!~)(?=.*[\\\\:*?”<>|/.])"
^ # Beginning of string
# Lookaheads to determine if;
(?! ~ ) # Not tilde at start
(?= .* [\\:*?”<>|/.] ) # Contains at least 1 of these chars