I have this line here:
\d(?!.*\d)
whereby it captures the last digit after a period. i.e: 6.3059
Will return "9", HOWEVER, what I really want it to do - is return 3.
Your regex matches any digit that is not followed by a digit, that is why you get 9
as output.
You can use a capturing group:
\d\.(\d)
The value will be in Group 1. See demo.
JS code:
var re = /\d\.(\d)/;
var str = '6.3059';
var m;
if ((m = re.exec(str)) !== null) {
document.getElementById("r").innerHTML = m[1];
}
<div id="r"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With