RegExp [^abc] Expression - Javascript RegExp

Javascript examples for RegExp:Bracket

Description

The [^abc] expression matches any character NOT between the brackets.

For example,

  • [abcde..] - Any character between the brackets
  • [A-Z] - Any character from uppercase A to uppercase Z
  • [a-z] - Any character from lowercase a to lowercase z
  • [A-z ]- Any character from uppercase A to lowercase z

[abc] expression matches any character between the brackets.

The following code shows how to Do a global search for characters that are NOT inside the brackets [h]:

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 ww .  j  a  v a  2 s  . co  m
    var str = "The following code shows how to ?!";
    var patt1 = /[^a-s]/gi;
    var result = str.match(patt1);
    document.getElementById("demo").innerHTML= result;
}
</script>

</body>
</html>

Related Tutorials