In JavaScript, how do I insert a newline character before every occurrence of a delimiter from a list of delimiters?
Example:
const delimiters = ['Q) ', 'A) ', 'B) ', 'C) ', 'E) ']
const str = 'Some textC) Some textE) Some text'
I want to create the String:
Some text
C) Some text
E) Some text
CodePudding user response:
You can solve this with a cheeky .replaceAll
and simple strings instead of regex