java - Having trouble with "replaceall" command -
i have string
s1 = "7+8";
and
s2 = "7+";
i using following code subtract s2 s1
system.out.println(s1.replaceall(s2,""));
but giving output as
"+8"
why happening??
the regular expression "7+"
matches 1 or more instances of "7"
. replaced, leaving "+8"
.
if want match exact strings, rather regular expressions, use replace
instead of replaceall
.
s1.replace(s2, "")
Comments
Post a Comment