D
D
dmitriyivvvv2018-04-11 18:32:21
JavaScript
dmitriyivvvv, 2018-04-11 18:32:21

Regular expression to remove spaces at the beginning/end of words?

How to compose a regular expression so that spaces are removed at the beginning of the line before the word (_word), at the end of the line after the word (word_) and replace double or more spaces between two words (word_word) with a single one.
Detailed example:
Source string (_word1_word2__word3_)
String that is needed as a result (word1_word2_word3)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2018-04-11
@dmitriyivvvv

You do not need regular expressions for this, there is an excellent trim function

S
Sanovskiy, 2018-04-11
@Sanovskiy

/(\s{2,}/
replace with one space

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question