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.

link|improve this question
feedback

1 Answer

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

string = string.replaceAll("stuff=\"-?\\d+\"", "stuff=\"0\"");
link|improve this answer
Thanks, let me try that. – joeybloey Sep 4 '09 at 2:38
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 Sep 4 '09 at 5:40
\w does not match a dash. Other than that I just ran the code, it replaces your example (stuff="-9888777666" , stuff="123") perfectly. – soulmerge Sep 4 '09 at 8:21
Yes that works. Thanks so much! – joeybloey Sep 4 '09 at 11:28
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.