I have the following function in javascript:
function unString(String){
var justNumbers = /(?=.*\d)\d*(?:\.\d*)?/;
var result = String.match(justNumbers);
result *= 1;
result = Math.round(result*100) / 100;
return result;
}
The meaning of it is to extract the number out of every possible css value, so that it can be added or substracted or multiplied with other values: e. g.
var newPadding = unString( $('#myID').css("padding-bottom") )*10 + "px";
Having modified my code I would now need the regex to allow an optional minus, to allow values like "-3px" be transformed to "-3" (actually the function can't and returns "0").
[I know there are tons of optional minus regex threads on stackoverflow and other forums, but they don't match the form of my regex - I do not have much experience with regex, for creating the above one I had to do long and intense research - and so I could not modify my regex, referring to these]
[The regex is should allow digits, optional decimal point and optional minus]
Thx in advance