views:

493

answers:

1

How can I replace all occurences of java substrings like stuff="-9888777666" , stuff="123", with the substring stuff="0"? The double quotes are actually a part of the string.

+3  A: 

Have a look at the regular expressions explanation in the java docs:

string = string.replaceAll("stuff=\"-?\\d+\"", "stuff=\"0\"");
soulmerge
Thanks, let me try that.
joeybloey
I tried this temp.replaceAll("stuff=\"\\w+\"", "stuff=\"0\"");But it does not work. The string remains as it was. Please note that there is a string enclosed within the double quotes in the substring stuff="foo".
joeybloey
\w does not match a dash. Other than that I just ran the code, it replaces your example (`stuff="-9888777666" , stuff="123"`) perfectly.
soulmerge
Yes that works. Thanks so much!
joeybloey