Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for selecting every white space

Tags:

c++

regex

What would look regex for selecting every white space? I've tried to do few combinations, including excluding nums, digits etc but to no avail.

like image 603
user336635 Avatar asked Dec 20 '11 09:12

user336635


People also ask

How do you restrict whitespace in regex?

You can easily trim unnecessary whitespace from the start and the end of a string or the lines in a text file by doing a regex search-and-replace. Search for ^[ \t]+ and replace with nothing to delete leading whitespace (spaces and tabs). Search for [ \t]+$ to trim trailing whitespace.

How do you check for space in regex?

The RegExp \s Metacharacter in JavaScript is used to find the whitespace characters. The whitespace character can be a space/tab/new line/vertical character. It is same as [ \t\n\r].

How do you skip a space in regex?

You can stick optional whitespace characters \s* in between every other character in your regex. Although granted, it will get a bit lengthy.


1 Answers

What about a simple

\s+

together with a match_all method or option, depending on your language?

See it here online on Regexr, the good place to test regular expressions

like image 84
stema Avatar answered Sep 20 '22 00:09

stema