regex - Java Regexp capturing group includes space, why? -
i trying parse string,
"æ¬éæªéµ æ©éæªé [zhan3 ding1 jie2 tie3] /to chop nail , slice iron (idiom)/resolute , decisive/unhesitating/definitely/without doubt/";
with code
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; }
however, reason string returned contains space @ end
org.junit.comparisonfailure: expected:<æ¬éæªéµ[]> was:<æ¬éæªéµ[ ]>
is there wrong pattern? have tried
private static final pattern traditional = pattern.compile("(.*?)\\s");
but no avail
i have tried matching 2 spaces @ end of pattern, doesn't match (there 1 space).
you're using matcher.group()
documented as:
returns input subsequence matched previous match.
the match includes space. capturing group within match doesn't, haven't asked that.
if change return statement to:
return matcher.group(1);
then believe it'll want.
Comments
Post a Comment