我需要一個符合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