I have a string like this "d2-23-543-56". It could be of any length, have any number of hyphens and will always end with an integer. I'm trying to come up with a regular expression that will match everything up to and including the last hyphen so that I can replace it with an empty string and have only the 56 left over, or whatever integer happens to be at the end of the string. I've been fooling around with a regular expression tester for hours trying to figure this out, anybody?
Hy, Maybe in this case you can use the split() method. Try this example: <script type="text/javascript"><!-- // by MarPlo - www.coursesweb.net var num = 'd2-23-543-56'; var ar_num = num.split('-'); var len_num = ar_num.length; alert(ar_num[len_num-1]); // 56 --></script> Code (markup):