pattern1
做我想做的事。它分割用点分隔的文本。我试图pattern
用于相同的目的,但$
似乎代表 $ 而不是输入结束。有什么建议让它发挥作用吗?
String pattern1 = "(\\w+)(?:\\.|$)";
String pattern = "(\\w+)[\\.$]";
Pattern regex = Pattern.compile(pattern);
Matcher matcher = regex.matcher("name.surname.value1.value");
while (matcher.find()) {
System.out.println(matcher.group(1));
}