In this tutorial, we will introduce you how to split a string using regular expressions in javascript. We will use split() method to implement it.
1.Create a string
const paragraph = 'The Answer to the Ultimate Question of Life, the Universe, and Everything is 42. Forty two. That's all there is.';
2.Split string by sentences
// Split by sentences const sentences = paragraph.split(/[!?.]/); console.log(sentences[1]);
Here /[!?.]/ is the regular expression.