I have a task to split the string. First, there are a few operations to perform
let currSynonyms = "['rear neck and choke', 'multiple fractures, multiple hairline injuries', 'leukemia']"
currSynonyms = currSynonyms.replace('[', '');
currSynonyms = currSynonyms.replace(']', '');
console.log(currSynonyms);
Output is this string:
'rear neck and choke', 'multiple fractures, multiple hairline injuries', 'leukemia'
Now I have to split this so that the 2nd element is not separated with the comma present there. So, my output should be an array like this:
['rear neck and choke', 'multiple fractures, multiple hairline injuries', 'leukemia']
If I do currSynonyms.split(',') I get:
[
"'rear neck and choke'",
" 'multiple fractures",
" multiple hairline injuries'",
" 'leukemia'"
]
If you do currSynonyms.length you'll get 4 but this is not what I want. I know I have to somehow use Regular expressions nut I can't figure out how?
', '. Is the problem more complex?