A
Arnaud Diederen
Hello everyone,
I had a look in the archives about this problem but maybe I'm not
using the proper terms in order to define my problem, and so I
couldn't find a solution.
I was just wondering if there was a regex that would help me split a
string of the form
"(0, 1, 2)"
into an array of 3 elements: ["0", "1", "2"]
and also split
"((0, 1, 2), (3, 4, 5), (6, 7, 8))"
into an array of 3 elements: ["(0, 1, 2)", "(3, 4, 5)", "(6, 7, 8)"]
I'm not an expert in regexes at all, and I couldn't find it.
Do I have to iterate on the input string and do the split myself, or
can someone provide with a solution?
Thank you very much,
Arnaud
PS: I just thought about that: replacing the '(' and ')' with '[' and
']' respectively, and then eval()'ing the thing to get n-deep
arrays.. but eval is evil, so I'd prefer not using it if possible.
--
Arnaud DIEDEREN
Software Developer
IONIC Software
Rue de Wallonie, 18 - 4460 Grace-Hollogne - Belgium
Tel: +32.4.3640364 - Fax: +32.4.2534737
mailto:[email protected]
http://www.ionicsoft.com
I had a look in the archives about this problem but maybe I'm not
using the proper terms in order to define my problem, and so I
couldn't find a solution.
I was just wondering if there was a regex that would help me split a
string of the form
"(0, 1, 2)"
into an array of 3 elements: ["0", "1", "2"]
and also split
"((0, 1, 2), (3, 4, 5), (6, 7, 8))"
into an array of 3 elements: ["(0, 1, 2)", "(3, 4, 5)", "(6, 7, 8)"]
I'm not an expert in regexes at all, and I couldn't find it.
Do I have to iterate on the input string and do the split myself, or
can someone provide with a solution?
Thank you very much,
Arnaud
PS: I just thought about that: replacing the '(' and ')' with '[' and
']' respectively, and then eval()'ing the thing to get n-deep
arrays.. but eval is evil, so I'd prefer not using it if possible.
--
Arnaud DIEDEREN
Software Developer
IONIC Software
Rue de Wallonie, 18 - 4460 Grace-Hollogne - Belgium
Tel: +32.4.3640364 - Fax: +32.4.2534737
mailto:[email protected]
http://www.ionicsoft.com