JavaScript RegExp Group [abc]
- Página anterior m
- Próxima página [^abc]
- Voltar à página anterior Manual de Referência JavaScript RegExp
Definition and Usage
The bracket [abc] specifies the matching item of the characters within the brackets.
Square brackets can define a single character, a group, or a character range:
[abc] | Any character a, b, or c. |
[A-Z] | Any character from uppercase A to uppercase Z. |
[a-z] | Any character from lowercase a to lowercase z. |
[A-z] | Any character from uppercase A to lowercase z. |
Example
Global search for the character "h" in the string:
let text = "Is this all there is?"; let pattern = /[h]/g;
Hint
Please use [^abc] The expression finds any character not within parentheses.
Example 1
Execute a global search for the characters "i" and "s" in the string:
let text = "Do you know if this is all there is?"; let pattern = /[is]/gi;
Exemplo 2
Busca global de caracteres de minúsculas "a" a minúsculas "h" na string:
let text = "Is this all there is?"; let pattern = /[a-h]/g;
Exemplo 3
Busca global do intervalo de caracteres de maiúsculas "A" a maiúsculas "E":
let text = "I SCREAM FOR ICE CREAM!"; let pattern = /[A-E]/g;
Exemplo 4
Busca global de caracteres de maiúsculas "A" a minúsculas "e" (pesquisa todas as maiúsculas, mas apenas as minúsculas de a a e).
let text = "I Scream For Ice Cream, is that OK?!"; let pattern = /[A-e]/g;
Exemplo 5
Busca global, insensível a maiúsculas e minúsculas, de caracteres no intervalo [a-s]:
let text = "I Scream For Ice Cream, is that OK?!"; let pattern = /[a-s]/gi;
Exemplo 6
Busca de caracteres "g" e "gi":
let text = "THIS This this"; let result1 = text.match(/[THIS]/g); let result2 = text.match(/[THIS]/gi);
Sintaxe
new RegExp("[abc])
ou abreviado:
/[abc]/
Sintaxe com modificador
new RegExp("[abc], "g")
ou abreviado:
/[abc]/g
Suporte do navegador
/[abc]/
É uma característica do ECMAScript1 (ES1).
Todos os navegadores suportam completamente o ES1 (JavaScript 1997):
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Suporte | Suporte | Suporte | Suporte | Suporte | Suporte |
Métodos de busca de expressão regular
No JavaScript, a busca de texto com expressões regulares pode ser feita com diferentes métodos.
UsoPadrão (pattern)Como expressão regular, esses são os métodos mais usados:
Exemplo | Descrição |
---|---|
text.match(padrão) | Método de string match() |
text.search(padrão) | Método de string search() |
padrão.exec(text) | Método RexExp exec() |
padrão.test(text) | Método RexExp test() |
- Página anterior m
- Próxima página [^abc]
- Voltar à página anterior Manual de Referência JavaScript RegExp