tags:

views:

58

answers:

3

i need to ignore anything that is one space, and empty space at least bigger than one space should be matched...

"MARY   HAD A LITTLE            LAMB"

i expect

"MARY", "HAD A LITTLE", "LAMB"
+3  A: 

Whitespace matching is \s and you can supply a minimum and maximum in curly braces. You can also omit either of them, like so:

\s{2,}

So your code would be like:

"MARY   HAD A LITTLE            LAMB".split(/\s{2,}/)

You can test it online here!

Brian McKenna
Thanks for the explanation Brian!
btelles
Very nice link. Thanks.
Gazler
+1  A: 

Use this: str.split(/\s{2,}/)

bryantsai
A: 
sed 's/  */ /g'

replaces one or more space..

so i guess regex is,

<space><space>*
shadyabhi