Javascript Data Type How to - Get number only from String with Regex








Question

We would like to know how to get number only from String with Regex.

Answer


<!DOCTYPE html>
<html>
<body>
<script type='text/javascript'>
<!--from  ww  w .j  a  v  a  2s .c o m-->
var t = "AA-12,AB-1,AC-11,AD-8,AE-30";
document.writeln(t.match(/\d+/g).join(','));

</script>
</body>
</html>

The code above is rendered as follows: