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
2009-09-03 18:33:11
Thanks, let me try that.
joeybloey
2009-09-04 02:38:48
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
2009-09-04 05:40:21
\w does not match a dash. Other than that I just ran the code, it replaces your example (`stuff="-9888777666" , stuff="123"`) perfectly.
soulmerge
2009-09-04 08:21:31
Yes that works. Thanks so much!
joeybloey
2009-09-04 11:28:38