Whitespace-Only Line in JS
Matches lines containing only whitespace (or empty lines).
Try it in the JS tester →Pattern
regexJS
^\s*$ (flags: gm)JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("^\\s*$", "gm");
const input = "line one\n \n\nline two";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
How the pattern works
`^\s*$` anchors to a full line that contains zero or more whitespace characters and nothing else.
Examples
Input
line one
line twoMatches