I was trying to match the last number in a string, such as “34” in
3.1 General definitions 34
I am using Python-style regex, and I have tried:
(.*?)(\d)
so that later I can use \1 to refer “3.1 General definitions ” and \2 to refer “34”.
But \2 matches “4” instead of “34”. So how shall I do?
Thanks and regards!
You’re currently only matching a single digit. Try
to match at least one digit. This should be all you need, as you’ve already made the first part of the match reluctant (non-greedy).
Depending on how you’re performing the match, you may need an “end of string” anchor ($) at the end, to make sure it doesn’t match the digits at the start of the string.