RegExp [^0-9] Expression matches any character that is NOT a digit. - Javascript RegExp

Javascript examples for RegExp:Bracket

Description

The [^0-9] expression matches any character that is NOT a digit.

The following code shows how to Do a global search for the numbers that are NOT 1 to 4 in a string:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from w w w  .ja  v a  2  s  .co m
    var str = "123456789";
    var patt1 = /[^1-4]/g;
    var result = str.match(patt1);
    document.getElementById("demo").innerHTML = result;
}
</script>

</body>
</html>

Related Tutorials