RegExp Characters [^abc]
A global search for characters that are NOT h:
let text = "Is this all there is?";
let pattern = /[^h]/g;
Try it Yourself »
Description
The /[^abc]/
expression matches any character NOT between the brackets.
RegExp Brackets
Brackets [] specifies matches for the characters inside the brackets.
Brackets can define single characters, groups, or character spans:
[a] | Matches the character a |
[abc] | Matches the characters a, b, or c |
[A-Z] | Matches all characters from uppercase A to uppercase Z |
[a-z] | Matches all characters from lowercase a to lowercase z |
[0-9] | Matches all digits from 0 to 9 |
Syntax
new RegExp("[^abc]")
or simply:
/[^abc]/
Syntax with modifiers
new RegExp("[^abc]", "g")
or simply:
/[^abc]/g
More Examples
A global search for characters that are NOT "i" or "s":
let text = "Do you know if this is all there is?";
let pattern = /[^is]/gi;
Try it Yourself »
Search for characters NOT from lowercase "a" to lowercase "h":
let text = "Is this all there is?";
let pattern = /[^a-h]/g;
Try it Yourself »
Search for characters NOT between uppercase "A" and uppercase "E":
let text = "I SCREAM FOR ICE CREAM!";
let pattern = /[^A-E]/g;
Try it Yourself »
Search for characters NOT between uppercase "A" and lowercase "e":
let text = "I Scream For Ice Cream, is that OK?!";
let pattern = /[^A-e]/g;
Try it Yourself »
A case-insensitive search for characters NOT between a and s:
let text = "I Scream For Ice Cream, is that OK?!";
let pattern = /[^a-s]/gi;
Try it Yourself »
Regular Expression Methods
Regular Expression Search and Replace can be done with different methods.
These are the most common:
String Methods
Method | Description |
---|---|
match(regex) | Returns an Array of results |
matchAll(regex) | Returns an Iterator of results |
replace(regex) | Returns a new String |
replaceAll(regex) | Returns a new String |
search(regex) | Returns the index of the first match |
split(regex) | Returns an Array of results |
RegExp Methods
Method | Description |
---|---|
regex.exec() | Returns an Iterator of results |
regex.test() | Returns true or false |
Browser Support
/[^abc]/
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |