I'm trying to find a way to parse chat text, and I'm having some issues. My purpose is to split the text into the fields (Date, Time, Name, Text) and get a statistic by Name, Date, and get number of words/letter in total for each person.
A sample would be this :
10/06/2019, 23:17 - Nasu Alex Taranu Gilmeanu: De iesit iesim cu siguranta. Dar tre sa cadem de acord la o varianta
10/06/2019, 23:17 - Dura Stefanel: Serios acum
10/06/2019, 23:18 - Dura Stefanel: E cea mai frumoasa cazare de pe site: din câte am văzut pana acum
11/06/2019, 00:04 - Nasu Alex Taranu Gilmeanu: http://www.booking.com/Share-CJY
11/06/2019, 18:31 - Danutz: Sa îl mănânci - cu Botu :)
The code I'm using is the one below, but I can't figure what the regex should be in order for it to:
- split by ": " and not by ":", so the time stays together.
- split only by first occurrence of the specified characters, as the split characters might be in the text to the right as well, and I only want to split the 4 fields
I load the stringData variable form a text file using Ajax, I just added str as a small sample of the data:
var stringData = $.ajax({
url: "http://localhost/_FunStuff/_ChatCounter/2021.01.04_textFile.txt",
async: false
}).responseText;
const str = `10/06/2019, 23:17 - Nasu Alex Taranu Gilmeanu: De iesit iesim cu siguranta. Dar tre sa cadem de acord la o varianta
10/06/2019, 23:17 - Dura Stefanel: Serios acum
10/06/2019, 23:18 - Dura Stefanel: E cea mai frumoasa cazare de pe site: din câte am văzut pana acum
11/06/2019, 00:04 - Nasu Alex Taranu Gilmeanu: http://www.booking.com/Share-CJY
11/06/2019, 18:31 - Danutz: Sa îl mănânci - cu Botu :)`;
function splitImportedData(stringData) {
$arrRows = stringData.split("\n");
for (rowi = 0; rowi < $arrRows.length; rowi++) {
var $strRow = $arrRows[rowi]
var $arrRow = $strRow.split(/[,:\s+\-]/);
if (rowi == 1) {
console.log($arrRow);
//alert($arrRow);
}
}
}
splitImportedData(str);