I’ve got a huge problem. I made a special ID for the things in our webpage. Let’s see an example:
H0059 – this is the special ID called registration number. The last two chars are the things’ id.
I’d like to cut off the useless characters, to get the real ID, what means strip the first char, and all the 0s before any other numbers.
Example:
L0745 => 745, V1754 => 1754, L0003 => 3, B0141 => 141, P0040 => 40, V8000 => 8000
Please help me in this.
I’ve tried with strreplace and explode but failed 🙁 Thanks for the help.
You can use:
Output:
Explanation of the regex used:
^[^1-9]*(.*?)$^– Anchor to start matching at thebeg of the string.
$– Anchor to match end of thestring.
[1-9]– A single non-zero digit[^1-9]– A single non 1-9 char…caninclude 0 or any other alphabet.
.*?– to match the rest()– group and remember…and use in replacement.This regex first by passes non 1-9 char at the beg of the string and matches and remembers the rest till the end …and replaces the whole string with the remembered thing.