Split Strings and Keep the Delimiter

JavaScriptPosted on

Splitting strings by a separator is a daily job for a developer. Usually, we don’t want to keep the delimiter, only the strings that have been glued by it. But still, there are some cases, when we want to keep them when splitting the string.

'one.two.three'.split(/(?<=\.)/); // ['one.', 'two.', 'three']

'one.two.three'.split(/(?=\.)/); // ['one', '.two', '.three']

You can see, we even have control, where to put the delimiter.

Need a web developer? Maybe we can help, get in touch!

Looking for web dev job?
You can check them on Jooble.

To see and write comments, you must allow the related (Disqus) cookies. For more information, please visit our privacy policy page.

Similar Posts

More content in JavaScript category