RegExp [abc] Expression matches any character between the brackets. - Javascript RegExp

Javascript examples for RegExp:Bracket

Description

The [abc] expression matches any character 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 NOT between the brackets.

The following code shows how to Do a global search for the character "h" 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 .  jav a 2 s .c o m
    var str = "this is a test abc 123 asdf123 321ewads";
    var patt1 = /[a-s]/gi;
    var result = str.match(patt1);
    document.getElementById("demo").innerHTML = result;
}
</script>

</body>
</html>

Related Tutorials