A
A
Antonio2022-02-24 13:45:14
Java
Antonio, 2022-02-24 13:45:14

How to escape quotes inside quotes?

Hello!
I am parsing data from Instagram in Java. The json returned by instagram is invalid because sometimes in some fields with naming inside quotes there are also quotes that are not escaped, for example:
"full_name": "Агроусадьба "Марусина Хата "",
Should be:
"full_name": "Агроусадьба \"Марусина Хата\"",

Maybe someone came across how you can escape quotes inside quotes using a regular expression?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vlad, 2022-02-24
@MoscowDriftss

" '' "
or
' "" '

M
Michael, 2022-02-24
@Akela_wolf

You can't do this with a regular. Since all sorts of fig cases are possible, for example:

"full_name": "Колхоз "Светлый путь", деревня Пролетарская", ...

or
"full_name": "Слева направо: "Москвич", "Волга", "Жигули"", ...

Any regular expression in such a heap of quotes, commas and colons (what can be used as reference characters for a regular expression) will simply get confused and either replace what is not needed, or not replace what is needed.

P
PavelMos, 2022-02-25
@PavelMos

Specifically, in this case, you can IMHO try to simply replace by known combinations through replace.
If there are two quotes in a string, replace with \""

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question