Given the following string
var log = `added 20-11-19 10:02 - Lucho Jara : Un golpe de suerte espero despierto. Canción: Luis Jara - Un golpe de suerte
added 21-12-20 11:52 - baby shark : Baby shark, doo doo doo doo doo doo`;;
The text with which I want to perform the explode is:added 20-11-19 10:02 - Lucho Jara :
The problem is that the date and time 20-11-19 10:02
can vary but they will keep the format ( added **-**-** **:** -
).
The name of the author after the date mentioned above can also vary (it is the same in length) - Lucho Jara :
but the separators - :
will always be kept.
Now, if we look at the description that follows, we realize that they could still contain the characters - :
for which a traditional explode will not work for us.
Can wildcards be used? Any efficient way to do this?
You could implement the js split method, something like:
const str = 'tu texto';
str.split("added").join(', ').split('-')
and from there moving what needs to be separated
Or with regular expressions:
(This example returns "added 20-11-19 10:02 - Lucho Jara :")