我正在尝试解析这个字符串,
"斬釘截鐵 斩钉截铁 [zhan3 ding1 jie2 tie3] /to chop the nail and slice the iron (idiom)/resolute and decisive/unhesitating/definitely/without any doubt/";
使用此代码
private static final Pattern TRADITIONAL = Pattern.compile("(.*?) ");
private String extractSinglePattern(String row, Pattern pattern) {
Matcher matcher = pattern.matcher(row);
if (matcher.find()) {
return matcher.group();
}
return null;
}
但是,由于某种原因,返回的字符串末尾包含一个空格
org.junit.ComparisonFailure: expected:<斬釘截鐵[]> but was:<斬釘截鐵[ ]>
我的模式有问题吗?我也试过
private static final Pattern TRADITIONAL = Pattern.compile("(.*?)\\s");
但无济于事
我也尝试在模式末尾匹配两个空格,但不匹配(只有一个空格)。