Reputation: 23
I'm trying to get an array with the following output:
["", "7", "02156567848", "CORTIER EP. ENGERANT ROSE JOSE MARIE", "059 NOMBRE DE LA PERSONA ES DIFERENTE"]
But using next code the result is different, because split is considering any non word character to separate the strings.
a = " 7 02156567848 CORTIER EP. ENGERANT ROSE JOSE MARIE. 059 NOMBRE DE LA PERSONA ES DIFERENTE"
b = a.split(/\W\W+/)
p b
Output:
["", "7", "02156567848", "CORTIER EP", "ENGERANT ROSE JOSE MARIE", "059 NOMBRE DE LA PERSONA ES DIFERENTE"]
Any idea how to solve this?
Thanks and regards!
Upvotes: 2
Views: 46
Reputation: 61875
Split on \s{2,}
-- two or more white-space characters.
a = " 7 02156567848 CORTIER EP. ENGERANT ROSE JOSE MARIE. 059 NOMBRE DE LA PERSONA ES DIFERENTE"
a.split(/\s{2,}/)
# => ["", "7", "02156567848", "CORTIER EP. ENGERANT ROSE JOSE MARIE.", "059 NOMBRE DE LA PERSONA ES DIFERENTE"]
Upvotes: 4