Page 1 of 1

Preg_Split / Regular Expressions

Posted: Thu Jun 22, 2006 2:53 pm
by cfytable
I need help with two string-splitting cases.

1) The first set of strings take the following form:
ABC111111, ZZZ2222222, XXXXX34536474

In this case, I would like the split to occur after the last occurence of an alphabetic letter. For instance, using the first two examples above:

Array[0] = ABC
Array [1] = 111111

Array[0] = XXXXX
Array [1] = 34536474

What regular expression would I use with preg_split in this case?

2) In the second case, there are some letters before and after a common number sequence. For instance:
EB1234666666, CBB123477777777

In this case, I would like to split the string after the '1234' sequence. For instance, using the first two examples above:

Array[0] = EB1234
Array [1] = 666666

Array[0] = CBB1234
Array [1] = 77777777

What regular expression would I use with preg_split in this case?

Any help would be appreciated.

Posted: Thu Jun 22, 2006 3:28 pm
by feyd
what have you tried so far?

Posted: Thu Jun 22, 2006 3:53 pm
by cfytable
Well, I tried the following for #2, but it's obviously not correct. It splits the string, but eliminates the '1234,' rather than store in the first array position. As I said, I'm not good with regular expressions.

$portions = preg_split('/1234/',$ID);

Posted: Thu Jun 22, 2006 3:56 pm
by feyd
Here's a tip: you don't actually want preg_split() here but preg_match().