Acoording to https://regex101.com/ regexp '^[-+]?[0-9]*\.?[0-9]$'
for strings like "g2", "a8" etc. (one digit preceded by one letter) should return "false" (no match), but if I use it in JavaScript using RegExp
test
method "true" is returned. What is the reason of that behaviour?
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var str = "g2";
var patt = new RegExp('^[-+]?[0-9]*\.?[0-9]$');
var res = patt.test(str);
document.getElementById("demo").innerHTML = res;
}
</script>
</body>
</html>