Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between \s and \t?

Tags:

regex

They both seem to work but I have been told you should use both when you're forming a RegExp?

like image 214
Evil Washing Machine Avatar asked Jul 30 '13 15:07

Evil Washing Machine


2 Answers

\s matches any whitespace character, including tabs. \t only matches a tab character.

\t being a subset of \s, you should not have to use both at the same time.

like image 173
Frédéric Hamidi Avatar answered Sep 18 '22 13:09

Frédéric Hamidi


\s matches a single whitespace character, which includes spaces, tabs, form feeds, line feeds and other unicode spaces.

\t Matches a single tab.

If you are using \s, you don't need to include \t.

More information on regex patterns here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

like image 36
talemyn Avatar answered Sep 19 '22 13:09

talemyn