A
Appr3nt1c3
Hello everyone,
How can I get the last numeric digits of a string? The string may
contain non-numeric characters but I only want to obtain the last part
that contains numbers.
Example:
Input: "0001"
Output: "0001"
Input: "001-0001"
Output: "0001"
Input: "001-A001"
Output: "001"
Input: "001-001A"
Output: "" or "0"
Input: "001-0001-1"
Output: "1"
I know than this can be done using by iterating each character in the
string and making if..else conditions for each character, but is there
a one-liner that can do this?
BTW, the output's length is not fixed.
Thanks,
Diego
How can I get the last numeric digits of a string? The string may
contain non-numeric characters but I only want to obtain the last part
that contains numbers.
Example:
Input: "0001"
Output: "0001"
Input: "001-0001"
Output: "0001"
Input: "001-A001"
Output: "001"
Input: "001-001A"
Output: "" or "0"
Input: "001-0001-1"
Output: "1"
I know than this can be done using by iterating each character in the
string and making if..else conditions for each character, but is there
a one-liner that can do this?
BTW, the output's length is not fixed.
Thanks,
Diego