8
I need patterns kb, Mb or Gb, I’m using regular expression (k|m|g)b$
and it has to be at the end of the line.
The test of my expression results in only 1 match when I test "20kb", but in this script the array has 2 positions. Why this occurs?
Script
<!DOCTYPE html>
<html>
<body>
<p id="p01">The best things in life are free!</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
text = document.getElementById("p01").innerHTML;
var re = "(k|m|g)b$";
var str = "20kb".trim().toLowerCase();
var myArray = str.match(re);
console.log(myArray);
document.getElementById("demo").innerHTML = myArray;
}
</script>
</body>
</html>
alternatively
[kmg]b$
?– JJoao