Q . How to check if a line is blank using regex?

Anuj Singh. asked, Jul 06 ' 2016

I am trying to make simple regex that will check if a line is blank or not.

Case;

"    some"   // not blank
"   " 	     //blank
"" 	         // blank

 

  • JavaScript
  • regex

1 Answers

The pattern you want is something like this in multiline mode:

^\s*$

Explanation:

  • ^ is the beginning of string anchor
  • $ is the end of string anchor
  • \s is the whitespace character class
  • * is zero-or-more repetition of

In multiline mode, ^ and $ also match the beginning and end of the line.

Leave a Ansewer