I’m trying to parse the values separated by commas in these 4 example sources
1,'Tambaú','Praça Santo António','Tambaú','12x0',2,'I','EM',12,6,5934,50
2,'Beira Rio','Av. Beira Rio, Prox. Av Odilon Coutinho','Beira Rio','12x0',2,'I','EM',12,0,7249,0
3,'Cabo Branco','Cabo Branco, Prox. Rua Alice de Almeida','Cabo Branco','12x0',2,'I','EO',12,0,4751,0
901,'teste','teste','teste','Mini-estação de demonstração',1,'I','EO',2,1,97,50`
I am using the regex ('?.*?'?), in Ruby. I can get the first and the last parsed like I want. However the problem with 2nd and 3rd is that there is a comma in the name (Av. Beira Rio, Prox. Av Odilon Coutinho and Cabo Branco, Prox. Rua Alice de Almeida). With my regex, these come out separated. For example I get Av. Beira Rio and Prox. Av Odilon Coutinho which is not what I want.
EDIT: I should have specified that this is not from a CSV file. It’s the parameters to a function from a web page source code.
You may use CSV and set
:quote_char => "'"to handle the separator inside your fields:If you don’t have a String but an Array as source, you need a little adaption:
As an alternative you may build a String:
Both methods expect an array with one-element-arrays.