Ομάδα RegExp [^abc] του JavaScript
- Προηγούμενη Σελίδα [abc]
- Επόμενη Σελίδα [0-9]
- Επιστροφή στο προηγούμενο επίπεδο Εκπαιδευτικός Οδηγός για JavaScript RegExp
Ορισμός και χρήση
Η παρένθεση [^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;
例子 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?";
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?";
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!";
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 any character range that is not [a-s]:
let text = "I Scream For Ice Cream, is that OK?!"; let pattern = /[^a-s]/gi;
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() |
- Προηγούμενη Σελίδα [abc]
- Επόμενη Σελίδα [0-9]
- Επιστροφή στο προηγούμενο επίπεδο Εκπαιδευτικός Οδηγός για JavaScript RegExp