Forum Moderators: phranque
/([[A-Za-z_-]+)(\d+)$/ /([\w-]+)(\d+)$/ /([\w-]*[^\d]+)(\d*)$/ What if there's a number within but at the very end of the string?
A while loop could work, or a single regex to only fetch the last digits and then strip that from the end of the string to get the first part.
while ($str =~ /[0-9]$/) {
($string, $number) = $str =~ /(.+)(\d)$/;
$append = $number . $append;
} do you also suggest leaving off the +?
I honestly don't understand why either work, anyway, so it's tough for me to read it and understand the logic.
@robzilla, do you mean at the end of the opening string?
the solutions suggested by lucy24 and i require that the first capture group ends in a non-digit character.
therefore the second capture group will contain any and all trailing digits in the string.
If there can be a number within the opening string, can't there also be a number at the very end of it?