Ομάδα RegExp [^abc] του JavaScript

Ορισμός και χρήση

Η παρένθεση [^abc] καθορίζει την ταινία που δεν περιλαμβάνεται μέσα στην παρένθεση.

Οι τελεστές μπορούν να ορίσουν μοναδικούς χαρακτήρες, ομάδες ή εύρος χαρακτήρων:

[^abc] Οποιοσδήποτε χαρακτήρας που δεν είναι a, b ή c
[^A-Z] Οποιοσδήποτε χαρακτήρας που δεν είναι από το Α έως το Ζ
[^a-z] Οποιοσδήποτε χαρακτήρας που δεν είναι από το a έως το z
[^A-z] Οποιοσδήποτε χαρακτήρας που δεν είναι από το Α έως το Ζ ή από το a έως το z

Hint:use [abc] expression to find any character between parentheses.

Παράδειγμα

Παράδειγμα 1

Για την αναζήτηση των χαρακτήρων που δεν βρίσκονται μέσα σε παρένθεση [h] σε ολόκληρο το κείμενο:

Perform a global search for any character range from lowercase "a" to lowercase "h":
let pattern = /[^h]/g;

try it yourself

例子 2

Example 2

Perform a global search for any character that is not "i" and "s":
let text = "Do you know if this is all there is?";

try it yourself

let pattern = /[^is]/gi;

Example 3

Perform a global search for any character range from lowercase "a" to lowercase "h":
let text = "Is this all there is?";

try it yourself

let pattern = /[^a-h]/g;

Example 4

Perform a global search for character ranges that are not from uppercase "A" to uppercase "E":
let text = "I SCREAM FOR ICE CREAM!";

try it yourself

let pattern = /[^A-E]/g;

Example 5

let text = "I Scream For Ice Cream, is that OK?!";
let pattern = /[^A-e]/g;

try it yourself

Example 6

Hint:Use [abc] expression to find any character between parentheses.

Perform a global, case-insensitive search for any character range that is not [a-s]:

let text = "I Scream For Ice Cream, is that OK?!";
let pattern = /[^a-s]/gi;

try it yourself

syntax

new RegExp("[^xyz])

or abbreviated:

/[^xyz]/

Syntax with modifiers

new RegExp("[^xyz]/g)

or abbreviated:

/[^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 with different methods.

usepattern (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()