Ho bisogno di un'espressione regolare (javascript compatibile) che possa corrispondere a qualsiasi stringa tranne una stringa che contiene solo spazi bianchi. Casi:Regex che corrisponde a qualsiasi cosa eccetto per tutti gli spazi bianchi
" " (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
Per curiosità, hai provato a cercare per questa prima? –
Sì, l'ho fatto, mi sono completamente dimenticato della versione negata di \ s però .. doh! Grazie a tutti quelli che hanno risposto! –
Invece di usare espressioni regolari, si potrebbe anche testare 'if (str.trim()) {// corrisponde}' – Shmiddty