[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Regular_expressions/Character_class [Back]  [Original]

: [...], [^...] - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

: [...], [^...]

Baseline

20157

v

regex
[]
[abc]
[A-Z]

[^]
[^abc]
[^A-Z]

// `v` 
[operand1&&operand2]
[operand1--operand2]
[\q{substring}]

operand1, operand2

Unicode \q

substring

v v v

/[a-zA-Z0-9]/

^ [^abc] abc ^ [a^b] a^b

/ /[/]/ /

js
/[\s-9]/u; // SyntaxError: Invalid regular expression: Invalid character class

Unicode 1 -

js
/[\s-9]/.test("-"); // true

Unicode BMP 1 2

js
/[]/.test("\ud83d"); // true
/[]/u.test("\ud83d"); // false

/[-]/.test(""); // SyntaxError: Invalid regular expression: /[-]/: Range out of order in character class
/[-]/u.test(""); // true

/[E-F]/i EFef /[E-f]/i ASCII EZ af [\]^_`

v

v . \]-

  • \b\B\b 2 \ \\
  • ] \]
  • (-) 2 [a-] a - [!--] ! - [--9] - 9 \-

v

v - v 1 2 [A-Z0-9] [A-Z] [0-9]

v && -- -- 2 [ \w--_] [\w&&[A-z]--_] [\w&&[[A-z]--_]] [[\w&&[A-z]]--_] [A-Za-z] [AB--C] [A[B--C]] [AB]

v Unicode \p \q{...} \q

  • ] \ ()[{}/-| ^$*+? / - / u
  • &&!!##$$%%**++,,..::;;<<==>>??@@^^``~~ v u v /[\!]/u /[\!]/v /[!]/v /[!!]/v

[^...] 1 [\q{ab|c}] "ab" [^\q{ab|c}] \q \p 1 /[^q{ab|c}--q{ab}]/v /[^c]/v

v [^...] [...] [^...] \P{...} \W

2

js
const r1 = /\p{Lowercase_Letter}/iu;
const r2 = /[^\P{Lowercase_Letter}]/iu;

r2 r1 r1 ASCII r2 Unicode ASCII r1 r2

js
const r1 = /[a-z]/iu;
const r2 = /[^A-Z]/iu;

ignoreCase r1 a-z ASCII r1 "A" "a" r2 A-Z a-z ^ [^A-Z] ASCII r2

v [^...] [^\P{Lowercase_Letter}] \p{Lowercase_Letter}

16

16

js
function isHexadecimal(str) {
  return /^[0-9A-F]+$/i.test(str);
}

isHexadecimal("2F3"); // true
isHexadecimal("beef"); // true
isHexadecimal("undefined"); // false

js
function greekLetters(str) {
  return str.match(/[\p{Script_Extensions=Greek}&&\p{Letter}]/gv);
}

//  is U+1018A GREEK ZERO SIGN
greekLetters("P0A"); // [ '', '', '' ]

ASCII

js
function nonASCIINumbers(str) {
  return str.match(/[\p{Decimal_Number}--[0-9]]/gv);
}

//  is U+11739 AHOM DIGIT NINE
nonASCIINumbers("01a"); // [ '', '' ]

\r\n (CRLF)

js
function getLineTerminators(str) {
  return str.match(/[\r\n\u2028\u2029\q{\r\n}]/gv);
}

getLineTerminators(`
A poem\r
Is split\r\n
Into many
Stanzas
`); // [ '\r', '\r\n', '\n' ]

/(?:\r|\n|\u2028|\u2029|\r\n)/gu or /(?:[\r\n\u2028\u2029]|\r\n)/gu

\q{}

js
function notUNSCPermanentMember(flag) {
  return /^[\p{RGI_Emoji_Flag_Sequence}--\q{||||}]$/v.test(flag);
}

notUNSCPermanentMember(""); // false
notUNSCPermanentMember(""); // true

/^(?!||||)\p{RGI_Emoji_Flag_Sequence}$/v

ECMAScript 2027 LanguageSpecification
# prod-CharacterClass


Web Proxy Viewer  |  New URL  |  Original Page