Referencias
Characters | Use |
---|---|
^ | Start of string, or start of line in multi-line pattern |
\A | Start of string |
$ | End of string, or end of line in multi-line pattern |
\Z | End of string |
\b | Word boundary |
\B | Not word boundary |
\< | Start of word |
\> | End of word |
abc | Matches any string that contains the ‘abc’ characters sequence on it |
Example | Description | Matching string examples |
---|---|---|
^A | Matches all the strings that start with an A | “An apple is in the tree”, “A new restaurant” |
end$ | Matches a string that ends with the ‘end’ sequence of characters | “The end”, “Let’s pretend” |
^Hello world$ | Matches the exact string ‘Hello world’ | “Hello world” |
order | Matches any string that contains the text ‘order’ in it | “My order number is 54” |
Los cuantificadores representan las veces que queremos que el símbolo o grupo de símbolos precedentes aparezcan en nuestra coincidencia
Characters | Use |
---|---|
* | Indicates zero or more |
+ | Indicates one ore more |
? | Indicates zero or one |
x{n} | Used to specify the number of times (‘n’) the previous character (‘x’) should appear |
x{n, } | Used to specify the minimum number of times (‘n’) the previous character (‘x’) should appear |
x{n, m} | Used to specify the minimum (‘n’) and maximum (’m') number of times the previous character (‘x’) should appear |
Añade ? a un cuantificador para hacerlo ungreedy
Example | Description | Matching string examples |
---|---|---|
hello!* | Matches any string ‘hello’ followed by zero or more ‘!’ characters | “hello”, “hello!”, hello!! |
hello!+ | Matches any string ‘hello’ followed by one or more ‘!’ characters | “hello!”, “hello!!” |
hello!? | Matches any string ‘hello’ followed by zero or one ‘!’ characters | “hello”, “hello!” |
(ha){2,4} | Matches any string that repeats the group of characters ‘ha’ two up to four times | “haha”, “hahaha”, “hahahaha” |
Characters | Use |
---|---|
a|b | Matches any string that contains either ‘a’ or ‘b’ |
[ ] | Is used to represent a list, so it matches a string that contains one of the characters inside the list |
Example | Description | Matching string examples |
---|---|---|
se(a|e) | Matches any string that contains the text ‘se’ followed either by an ‘a’ or an ‘e’ | “see”, “sea” |
a[bcd] | Matches any string that contains an ‘a’ followed either by ‘b’, ‘c’, or ’d' | “ab”, “ac”, “ad” |
Los operadores de clases de caracteres permiten hacer coincidir caracteres dentro de una categoría (clase). Estos operadores ofrecen sus negaciones, que son las mismas que las del operador normal pero en mayúsculas.
Characters | Use |
---|---|
\d | Matches a single digit character |
\w | Matches a single word character (letters, numbers, and underscore) |
\s | Matches a single white space character, including tabs and line breaks |
\D | Matches a single non-digit character |
\W | Matches a single non-word character (letters, numbers, and underscore) |
\S | Matches a single non-white space character, including tabs and line breaks |
. | Matches any single character |
En regex generalmente se usa la forma /pattern/. Al final, podemos usar las siguientes banderas:
Flag | Description |
---|---|
g | The global flag is used to search for all the individual matches inside the string. If it is not used, the expression will return after the first match |
m | The multiline flag allows to use ^ and $ as the beginning and end of a line, not the beginning and end of the string, which can contain multiple lines |
i | The insensitive flag makes the regular expression case insensitive |
Inteligencia de Amenazas - Anterior
Trackers de Campañas y Malware
Próximo - RegEx
Biblioteca de Expresiones
Última actualización 1yr ago