Languages
[Edit]
EN

JavaScript - split string with more than 1 space between words

0 points
Created by:
telsa
502

In this article, we would like to show you how to split a string with more than 1 space between words in JavaScript.

Quick solution:

 

1. Split by one or more whitespace characters regex - \s+

Edit

In this example, we use \s+ regex to split the text string by one or more whitespace characters between words.

Runnable example:

 

2. Split string from 2 to 8 spaces using \s{2,8} regex

Edit

In this example, we use \s{2,8} regex to split the text string that contains from 2 to 8 whitespace characters between words.

Runnable example:

Note:

Notice that A B is a single element because there is only one space character between the letters.

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - split string with more than 1 space between words

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join