preg_split or preg_match - need to include delimiter

Thanks in advance to whoever can help me!

I guess this might be an easy question but I'm horrible with regular expressions. I need to split all of the authors inside an XML tag by a number that follows the authors name but I ALSO NEED TO INCLUDE THE NUMBER in the match that is outputted. So something like this:

<authors>joe smith1 jane doe2 jack johnson3</authors>

array {
[0]=> joe smith1
[1]=> jane doe2
[2]=> jack johnson3

I need to do the same with affiliations but the number is in the front this time:

<affiliations>1 university of nowhere 2 ministry of silly walks 3 pcu</affiliations>

array {
[0]=> 1 university of nowhere
[1]=> 2 ministry of silly walks
[2]=> 3 pcu

How can I do this using preg_match, preg_split or some other reg ex matching solution?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sherlock5Author Commented:
yeah, i tried that before but the delimiter wasn't included in the output:

$author_array = preg_split("/(\d{1,2})/", $r["Authors"], -1, PREG_SPLIT_DELIM_CAPTURE);

Array ( [0] => Joe Smith [1] => 1 [2] => Jane Doe [3] => 1 [4] => )

is there some other setting that i am missing? i need it to output like this:

Array ( [0] => Joe Smith1 [1] => Jane Doe2 )
This code seems to match your data:
$authorblock='<authors>joe smith1 jane doe2 jack johnson3</authors>';
$author_array = preg_split('/([^\d]*\d{1,2} )/',preg_replace('/(?:^<authors>|<\/authors>$)/','',$authorblock), -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
echo '<pre>'.htmlentities(print_r($author_array,true));
$affliationsblock='<affiliations>1 university of nowhere 2 ministry of silly walks 3 pcu</affiliations>';
$affiliation_array = preg_split('/(\d{1,2} [^\d]*)/',preg_replace('/(?:^<affiliations>|<\/affiliations>$)/','',$affliationsblock), -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
echo '<pre>'.htmlentities(print_r($affiliation_array,true));

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sherlock5Author Commented:
thanks for the help! that did the trick!
Thanks for the question and the points.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.