How to convert String that contains quotes in same string, using replaceAll?

4

I have a String as in the example below

String a = "Meu pai é um Grande "baio" de fada";

I want to make it turn a String like this

String a = "Meu pai é um Grande \"baio\" de fada";

How do I do this using replaceAll?

    
asked by anonymous 24.06.2015 / 21:07

1 answer

6

replaceAll in the quotation marks

It would be something like:

String a = "Meu pai é um Grande "baio" de fada";
a = a.replaceAll("\"", "\\"");

In this case you will change any quotation marks found, regardless of whether it is "test or "test" .

replaceAll between the quotation marks

But your question seems to me that it is more with RegEx, the use I believe it to be this:

String a = "Meu pai é um Grande "baio" de fada";
a = a.replaceAll("\"([^\"]+)\"", "\"$1\"");

In this case, you will look for all those within the quotation marks, such as "?asd?asd/A/sd;;lasd"

replaceAll between quotation marks that contain text

In case it can be something with with texts:

String a = "Meu pai é um Grande "baio" de fada";
a = a.replaceAll("\"([a-zA-Z0-9\s]+)\"", "\"$1\"");

In this case, you will look for all those within the quotation marks, such as "a e 0 9"

    
24.06.2015 / 21:14