Split whole text into javascript chunks

2

Good afternoon guys from stackoverflow

I'm having to split the text I get from a return from an ajax. This my return has the following pattern

It starts with what will be the value, the rest will be the content of an option, ending in the queue or available positions, as the example below.

222/05/2017 a 26/05/2017 em Belo Horizonte - PaperCut MF Técnico Presencial (34 hrs) - Fila de espera307/08/2017 a 11/08/2017 em Belo Horizonte - PaperCut MF Técnico Presencial (34 hrs) - Vagas disponíveis

How can I do this division ... I am without ideas, I only need the logical reasoning for this ...

    
asked by anonymous 24.03.2017 / 18:08

1 answer

2

Although I think this return is a array , I've managed to sort it out like this:

var response = "222/05/2017 a 26/05/2017 em Belo Horizonte - PaperCut MF Técnico Presencial (34 hrs) - Fila de espera307/08/2017 a 11/08/2017 em Belo Horizonte - PaperCut MF Técnico Presencial (34 hrs) - Vagas disponíveis";

var data = response.split(/(\d+)(?=(?:\d{2}\/\d{2}\/\d{4}\sa))/);

var obj = {};
for(var i = 1; i < data.length; i++) {
  obj[data[i]] = data[++i];  
}

console.log(obj);

In this way the variable obj will receive the id as key and the corresponding text as value .

    
24.03.2017 / 19:29