Last Updated : 11 Jul, 2025
The RegExp \S Metacharacter in JavaScript is used to find the non-whitespace characters. The whitespace character can be a space/tab/new line/vertical character. It is the same as [^\t\n\r].
JavaScript
let str = "Geeky@128";
let regex = new RegExp("\\S", "g");
let match = str.match(regex);
console.log(match);
[ 'G', 'e', 'e', 'k', 'y', '@', '1', '2', '8' ]Syntax
/\S/
// or
new RegExp("\\S")
Syntax with modifiers
/\S/g
// or
new RegExp("\\S", "g")
Example 1: Matches the non-whitespace characters.
JavaScript
let str = "GeeksforGeeks @ _123_ $";
let regex = /\S/g;
let match = str.match(regex);
console.log(match);
[ 'G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's', '@', '_', '1', '2', '3', '_', '$' ]
Example 2: Matches the non-whitespace strings.
JavaScript
const regex = /\S+/g;
const str = "Hello World! This is JavaScript";
const matches = str.match(regex);
console.log(matches);
[ 'Hello', 'World!', 'This', 'is', 'JavaScript' ]Supported Browsers
We have a complete list of Javascript RegExp expressions, to check those please go through this JavaScript RegExp Complete Reference article.
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4