Friday, 23 August 2013

Split a string to groups of 2 chars using split?

Split a string to groups of 2 chars using split?

I have this simple string :
"a1a2a3"
Is there any regex expression which can be used with split command so it
will split the string to a pairs ? :
["a1","a2","a3"] ?
I've tried this :
"a1a2a3".split(/(?=..)/)
But it returns ["a", "1", "a", "2", "a3"]
p.s.
I can do it with Match but im looking (if exists) for the regex expression
which can help me using split.

No comments:

Post a Comment