这里的Groovy 2.4。我有一个我想要匹配的字符列表,特别是:
`;[]&<>?:()\x{e76f}
我最好的尝试:
import java.util.regex.Matcher;
Matcher matcher
String illNameChars = /[`\/;\[\]&<>?:\()|-]+/
String input = "Bupo;dupo"
if(input) {
matcher = input =~ illNameChars
if(matcher.matches()) {
println "Illegal character detected!"
}
}这适用于第一个字符( "`")和第二个字符(";"),而不是第三个字符("[")...any想法为什么?
发布于 2016-05-10 16:42:34
你在双倍地逃脱牙套:
尝试:
import java.util.regex.Matcher;
String input = "["
Matcher matcher = input =~ /[`\/;\[\]&<>?:\()|-]+/
if(matcher.matches()) {
println "Matched!"
} else {
println "No match!"
}只注意和字符的一个转义。这导致了一场比赛,当我运行它。
https://stackoverflow.com/questions/37144191
复制相似问题