我需要一个符合JavaScript的正则表达式,它将匹配除了仅包含空格的字符串之外的任何字符串。案例:正则表达式匹配除了所有空格之外的任何内容
" " (one space) => doesn't match
" " (multiple adjacent spaces) => doesn't match
"foo" (no whitespace) => matches
"foo bar" (whitespace between non-whitespace) => matches
"foo " (trailing whitespace) => matches
" foo" (leading whitespace) => matches
" foo " (leading and trailing whitespace) => matches
出于好奇,你尝试寻找这首? –
是的,我完全忘了\ s的否定版本..虽然.. doh!感谢所有回复的人! –
而不是使用正则表达式,你也可以测试'if(str.trim()){//匹配}' – Shmiddty