开发者

Need a Regular expresssion that should not allow only space in string, It can allow spaces along with characters

开发者 https://www.devze.com 2023-03-09 17:48 出处:网络
Need a Regular expresssion that should not allowonly spacein str开发者_开发百科ing, It can allow spaces alongwith characters.

Need a Regular expresssion that should not allow only space in str开发者_开发百科ing, It can allow spaces along with characters.

e.g: space+char+space is allowed where as only space is not allowed


/\S/ is sufficient to match a non-empty string.


Try this:

/^\s+$\

Any string that matches the above expression is invalid as per your criteria.


Maybe it's easier and faster to test the emptiness of the string after using trim() on it.


If you're just looking for a positive match:

/\S/

If you want to capture:

/(.*\S.*)/

EDIT:

Actually, if you meant a literal space:

/[ ]/


You simply have to enforce a non-space character appearing at least once:

\s*\S+\s*

0

精彩评论

暂无评论...
验证码 换一张
取 消