Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
re.regex
Puedes definir la coincidencia de expresiones regulares en YARA-L 2.0 con cualquiera de las siguientes sintaxis:
Uso de la sintaxis de YARA-L: Se relaciona con los eventos.
A continuación, se muestra una representación genérica de esta sintaxis:
$e.field = /regex/
Usa la sintaxis de YARA-L como una función que toma los siguientes parámetros:
- Campo al que se aplica la expresión regular.
- Expresión regular especificada como una cadena.
A continuación, se muestra una representación genérica de esta sintaxis:
re.regex($e.field, `regex`)
Descripción
Esta función devuelve true
si la cadena contiene una subcadena que coincide con la expresión regular proporcionada. No es necesario agregar .*
al principio ni al final de la expresión regular.
Notas
- Para que coincida la cadena exacta o solo un prefijo o sufijo, incluye los caracteres de anclaje
^
(inicial) y $
(final) en la expresión regular.
Por ejemplo, /^full$/
coincide exactamente con "full"
, mientras que /full/
podría coincidir con "fullest"
, "lawfull"
y "joyfully"
.
- Si el campo de UDM incluye caracteres de salto de línea,
regexp
solo coincide con la primera línea del campo de UDM. Para aplicar la coincidencia completa de los campos de UDM, agrega un (?s)
a la expresión regular. Por ejemplo, reemplaza /.*allUDM.*/
por /(?s).*allUDM.*/
.
- Puedes usar el modificador
nocase
después de las cadenas para indicar que la búsqueda debe ignorar el uso de mayúsculas.
Tipos de datos de parámetros
STRING
, STRING
Tipos de expresiones de parámetros
ANY
, ANY
Tipo de datos que se muestra
BOOL
Muestras de código
Ejemplo 1
// Equivalent to $e.principal.hostname = /google/
re.regex($e.principal.hostname, "google")
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-07-29 (UTC)
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-07-29 (UTC)"],[[["\u003cp\u003eThe \u003ccode\u003ere.regex\u003c/code\u003e function in YARA-L 2.0 is used to check if a string contains a substring that matches a given regular expression, and is supported in Rules and Search.\u003c/p\u003e\n"],["\u003cp\u003eThere are two ways to define regular expression matching in YARA-L 2.0: using the \u003ccode\u003e$e.field = /regex/\u003c/code\u003e syntax or by using the \u003ccode\u003ere.regex($e.field, \u003c/code\u003eregex\u003ccode\u003e)\u003c/code\u003e function.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ere.regex\u003c/code\u003e function automatically checks for substrings, so adding \u003ccode\u003e.*\u003c/code\u003e at the beginning or end of the regular expression is unnecessary.\u003c/p\u003e\n"],["\u003cp\u003eTo ensure exact string matching or to match prefixes or suffixes, use the \u003ccode\u003e^\u003c/code\u003e and \u003ccode\u003e$\u003c/code\u003e anchor characters within the regular expression, and add a \u003ccode\u003e(?s)\u003c/code\u003e modifier for full multi-line field matching.\u003c/p\u003e\n"],["\u003cp\u003eThe function supports case-insensitive searches using the \u003ccode\u003enocase\u003c/code\u003e modifier after the strings.\u003c/p\u003e\n"]]],[],null,["### re.regex\n\nSupported in: \n[Rules](/chronicle/docs/detection/default-rules) [Search](/chronicle/docs/investigation/udm-search)\n\nYou can define regular expression matching in YARA-L 2.0 using either of the following syntax:\n\n- Using YARA-L syntax --- Related to events.\n The following is a generic representation of this syntax:\n\n $e.field = /regex/\n\n- Using YARA-L syntax --- As a function taking in the following parameters:\n\n - Field the regular expression is applied to.\n - Regular expression specified as a string.\n\n The following is a generic representation of this syntax: \n\n re.regex($e.field, `regex`)\n\n#### Description\n\nThis function returns `true` if the string contains a substring that matches the regular expression provided. It is unnecessary to add `.*` to the beginning or at the end of the regular expression.\n\n##### Notes\n\n- To match the exact string or only a prefix or suffix, include the `^` (starting) and `$` (ending) anchor characters in the regular expression. For example, `/^full$/` matches `\"full\"` exactly, while `/full/` could match `\"fullest\"`, `\"lawfull\"`, and `\"joyfully\"`.\n- If the UDM field includes newline characters, the `regexp` only matches the first line of the UDM field. To enforce full UDM field matching, add a `(?s)` to the regular expression. For example, replace `/.*allUDM.*/` with `/(?s).*allUDM.*/`.\n- You can use the `nocase` modifier after strings to indicate that the search should ignore capitalization.\n\n#### Param data types\n\n`STRING`, `STRING`\n\n#### Param expression types\n\n`ANY`, `ANY`\n\n#### Return type\n\n`BOOL`\n\n#### Code samples\n\n##### Example 1\n\n // Equivalent to $e.principal.hostname = /google/\n re.regex($e.principal.hostname, \"google\")"]]