【发布时间】:2013-03-03 00:52:41
【问题描述】:
我的目标是读取字符串并忽略括号中的文本。
public static void main(String[] args) {
Pattern checkRegex= Pattern.compile("([a-zA-Z]{3,30}\\s*){2}");
Matcher regexMatcher=checkRegex.matcher("James Hunt(Skateboarder)");
while(regexMatcher.find()){
System.out.println(regexMatcher.group().trim());
}
当前输出为:
詹姆斯·亨特
滑板手
基本上我想要的只是输出“James Hunt”。 在这种情况下,什么是合适的正则表达式模式?
【问题讨论】: