Sometimes, we want to use JavaScript regex to split by line.
In this article, we’ll look at how to use JavaScript regex to split by line.
How to use JavaScript regex to split by line?
To use JavaScript regex to split by line, we can call the string split
method with a regex.
For instance, we write
const result = subject.split(/\r?\n/);
to call subject.split
with a regex that matches \r\n
or \n
and return an array with the substrings between the new line characters.
Conclusion
To use JavaScript regex to split by line, we can call the string split
method with a regex.