8

Split Strings and Keep the Delimiter

 3 years ago
source link: https://pineco.de/snippets/split-strings-and-keep-the-delimiter/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Split Strings and Keep the Delimiter

We use cookies for commenting and analytics. For more details, please visit our privacy page.

Ugrás a tartalomhoz

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.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK