开发者

Whats the regexp to detect a string with at least 6 characters and without whitespace?

开发者 https://www.devze.com 2023-03-31 09:42 出处:网络
I\'m still learning regexp and I was wondering what the regexp would look like for detecting a string with at least 6 characters and without any whitespace?

I'm still learning regexp and I was wondering what the regexp would look like for detecting a string with at least 6 characters and without any whitespace?

I'm using javascript, so why doesn't this work?

if (VAL.match( /^\S{6,}$/) ) ret开发者_如何学Pythonurn true;


You can match a whitespace character with a \s, and a non-whitespace character with \S. So this should work for you:

/^\S{6,}$/

However you didn't specify the flavor of regex you're using. You may need to escape the bracket or use another character class if \S is not available.

EDIT (Lars): The question was "at least 6 characters" - modified to {6,}


Try the following regex:

/^\S{6,}$/
0

精彩评论

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