
求大神帮忙给个正则表达式,java的,怎么写idea都字符串报错,木有办法
首先,正则的思路应该是我支持什么样的格式。根据问题,假设是支持字母(不限大小写)、数字、以及符号-#
那么正则表达式是:[A-Za-z0-9-#]{1,64},如果要支持更多的字符,请在#后面添加即可
Java代码示例:
import java.util.regex.*;
boolean foundMatch = false;
try {
Pattern regex = Pattern.compile("[A-Za-z0-9-#]{1,64}");
Matcher regexMatcher = regex.matcher(subjectString);
foundMatch = regexMatcher.find();
} catch (PatternSyntaxException ex) {
// 异常处理