How to get value of xml tag using preg_match?

I receive xml in a single numeric value either
...
<factor>1234</factor>
...

either
...
<Reference type="0">1234</Reference>
...


I need to take it down and take it is highly desirable, one of the regular season.
the problem with the following code
preg_match('/<factor>(\d+)<\/factor>|<Reference type="\d+">(\d+)<\/Reference>/', $response, $matches);

that he is in $matches[1] records only the value of the factor, and $matches[2] only reference (despite the fact that these two tags are never found in the same xml document). I it is highly desirable that in both cases the entry was only in $matches[1]
April 7th 20 at 11:01
1 answer
April 7th 20 at 11:03
Solution
He decided:
<(?>factor|Reference type="\d+")>(\d+)<\/(?>factor|Reference)>

Find more questions by tags PHPRegular expressions