2

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.

1 Answer 1

4

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

string = string.replaceAll("stuff=\"-?\\d+\"", "stuff=\"0\"");
Sign up to request clarification or add additional context in comments.

2 Comments

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".
\w does not match a dash. Other than that I just ran the code, it replaces your example (stuff="-9888777666" , stuff="123") perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.