Q:

Separate number following underscore off end of string? Regex?

I'm an ob-c programmer who needs some php for his current project. I'm guessing I need to use Regex for my current problem, but I have never used Regex and it has proven a lot to bite off in one go, for a single problem. Similar questions I have found on SO haven't helped me solve my problem as generally they are written for people with a fair idea of how to do something like this, and as I said, I am a total newbie in this area.
My problem is this:
I have a string, that ends with an underscore followed by a number:
$string = XXXXXXXX_123
I want to separate this into two strings:
$root = XXXXXXXX_
and
$number = 123
Things are slightly more complicated in that:

the XXXXXX could contain other underscores or digits (e.g.. the full thing could be XX_X12_9_123, in which case I would want to separate it into XX_X12_9_ and 123. (The underscore that I want to divided after will always be the last underscore.)
the number at the end could be any number of digits long (although it will be a minimum of 1)

(In case you haven't guessed, these are file names that need to be incremented)
thanks for your time

A:

$pos = strrpos($string, '_') + 1;
$root = substr($string, 0, $pos);
$number = substr($string, $pos);

