Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex matching all but not empty

Tags:

regex

A line has to be validated through regex,

  1. line can contain any characters, spaces, digits, floats.

  2. line should not be blank

I tried this:

[A-Za-z0-9~`!#$%^&*()_+-]+ //thinking of all the characters

Any alternative solution will be helpful

like image 545
FirmView Avatar asked Jul 23 '12 19:07

FirmView


2 Answers

Try this to match a line that contains more than just whitespace

/.*\S.*/

This means

/ = delimiter
.* = zero or more of anything but newline
\S = anything except a whitespace (newline, tab, space)

so you get
match anything but newline + something not whitespace + anything but newline

if whitespace only line counts as not whitespace, then replace the rule with /.+/, which will match 1 or more of anything.

like image 175
Timo Huovinen Avatar answered Sep 20 '22 05:09

Timo Huovinen


try:

.+

The . matches any character, and the plus requires least one.

like image 32
B.K. Avatar answered Sep 19 '22 05:09

B.K.