6
I’m trying to use a regex to separate the texts separated by space, except those inside quotes, for example:
Entrada: texto1 texto2 "texto3 texto4" texto5
Saida: Array("texto1", "texto2", "texto3 texto4", "texto5" );
Entrada: "texto0 texto1 texto2" texto3 "texto4"
Saida: Array("texto0 texto1 texto2", "texto3", "texto4" );
Entrada: "texto0 texto1" texto2
Saida: Array("texto0 texto1", "texto2");
Entrada: texto0 texto1 "texto2 texto3"
Saida: Array("texto0", "texto1", "texto2 texto3");
Not belittling the other answers, but I think that every response involving regex should be like this, explaining in detail how it works, it helps the most laity (like myself) to understand what is happening, not just copy and use.
– user28595
Every time I get lost in these parameters.
– NoobSaibot
For those who like to view blocks and diagrams (Usually people connected to programming feel ease), a site recommended for better visualization of Regex is the Debuggex. In which an example can be seen in this link.
– danieltakeshi
@danieltakeshi I don’t know why but I like this one better: https://regexr.com/3ls5g rs
– Sam
I also like this and the Regex101, but I think for those who are learning, the use of both is very valid. I used both when I was learning. Because the formatting colors and explanation of Regex101/Regexr are complemented with the visualization of the Debuggex
– danieltakeshi