Preciso de padrões de kb, mb ou gb, estou utilizando a expressão regular (k|m|g)b$
e tem que estar no final da linha.
O teste da minha expressão resulta em somente 1 match quando testo "20kb", porém nesse script o array possui 2 posições. Por que isso ocorre?
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>