java - replaceAll Dangling metacharacter -


this question has answer here:

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