Question:
Small question regarding some string manipulation please.I have a file which lines sometimes contains a large number of spaces (the character space), always more than two.
But it also contains valid phrases, where words are separated by one space only.
Example:
['a good sentence where words are separated by one character space only']
Above is the example for one line, the files contains many of those lines. Each line therefore also has a “line break” character which I would like to preserve.
What I would like to achieve is pretty simple, in a “find & replace” option which allow me to input a regex, I would like to give it a regex which says:
For all the sequences of spaces that are more than 2, just remove them. For the normal spaces, 1 space only, keep them. Keep also the line breaks.
Expected result:
['a good sentence where words are separated by one character space only']
I tried this regex:
\ \.*
But it is not yielding any result.
This question is for a simple text editor which offers the option replace in text by regular expression. I am not using any programming language to do so.
May I ask what would be the correct regex in this context please?
Thank you
Answer:
You need to:\s{2,}
replace to
(1 space)or
{2,}
(space two or more times) replace to
(1 space).\s
is
(space), \n
(new line), \t
(tab) and other space charsIf you have better answer, please add a comment about this, thank you!