this question has answer here:
- replace string in java 5 answers
i have string, 1++++----2 , want replace ++++---- string, string. use java function replaceall, keep warning dangling metacharacter every time use it:
mystring.replaceall("++++----", "string");
you can use following regex :
mystring.replaceall("\\++-+", "string") since + regex character need escape it.so here in "\\++-+" first part \\+ match character + literally , second + match 1 or more combination of character + , rest -+ match 1 or more -.
Comments
Post a Comment