JavaScript RegExp Group [^abc]
- Previous Page [abc]
- Next Page [0-9]
- Go Up One Level JavaScript RegExp Reference Manual
Definition and Usage
The bracket [^abc] specifies the matching item for any character not within the brackets.
Square brackets can define a single character, a group, or a character range:
[^abc] | Not any of the characters a, b, or c |
[^A-Z] | Any character not from uppercase A to uppercase Z |
[^a-z] | Any character not from lowercase a to lowercase z |
[^A-z] | Any character not from uppercase A to lowercase z |
Hint:use [abc] expression to find any character between parentheses.
Instance
Example 1
Perform a global search on characters not within the brackets [h]:
Perform a global search for the range of characters from lowercase "a" to lowercase "h" in the string: let pattern = /[^h]/g;
Example 2
Perform a global search for characters that are not "i" and "s" in the string: let text = "Do you know if this is all there is?";
let pattern = /[^is]/gi;
Example 3
Perform a global search for the range of characters from lowercase "a" to lowercase "h" in the string: let text = "Is this all there is?";
let pattern = /[^a-h]/g;
Example 4
Perform a global search for characters that are not in the range from uppercase "A" to uppercase "E": let text = "I SCREAM FOR ICE CREAM!";
let pattern = /[^A-E]/g;
Example 5
let text = "I Scream For Ice Cream, is that OK?!"; let pattern = /[^A-e]/g;
Example 6
Hint:Use [abc] expression to find any character between parentheses.
Perform a global, case-insensitive search for the range of characters that are not [a-s]:
let text = "I Scream For Ice Cream, is that OK?!"; let pattern = /[^a-s]/gi;
syntax
new RegExp("[^xyz]
or abbreviated as:
/[^xyz]/
语法 with modifiers
new RegExp("[^xyz]", "g")
or abbreviated as:
/[^xyz]/g
hint
use [abc] expression to find any character between parentheses.
browser support
/[^abc]/
is ECMAScript1 (ES1) feature.
All browsers fully support ES1 (JavaScript 1997):
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
supported | supported | supported | supported | supported | supported |
Regular expression search methods
In JavaScript, regular expression text search can be completed using different methods.
usagepattern (pattern)As regular expressions, these are the most commonly used methods:
example | description |
---|---|
text.match(pattern) | string method match() |
text.search(pattern) | string method search() |
pattern.exec(text) | RexExp method exec() |
pattern.test(text) | RexExp method test() |
- Previous Page [abc]
- Next Page [0-9]
- Go Up One Level JavaScript RegExp Reference Manual