Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
re.regex
É possível definir a correspondência de expressões regulares em YARA-L 2.0 usando uma das seguintes sintaxes:
Usando a sintaxe YARA-L — relacionada a eventos.
Confira a seguir uma representação genérica dessa sintaxe:
$e.field = /regex/
Usando a sintaxe YARA-L como uma função que recebe os seguintes parâmetros:
- Campo em que a expressão regular é aplicada.
- Expressão regular especificada como uma string.
Confira a seguir uma representação genérica dessa sintaxe:
re.regex($e.field, `regex`)
Descrição
Essa função retorna true
se a string contiver uma substring que corresponda à expressão regular fornecida. Não é necessário adicionar .*
no início ou no fim da expressão regular.
Observações
- Para corresponder à string exata ou apenas a um prefixo ou sufixo, inclua os caracteres âncora
^
(inicial) e $
(final) na expressão regular.
Por exemplo, /^full$/
corresponde exatamente a "full"
, enquanto /full/
pode corresponder a
"fullest"
, "lawfull"
e "joyfully"
.
- Se o campo da UDM incluir caracteres de nova linha, o
regexp
só vai corresponder à
primeira linha do campo. Para forçar a correspondência completa do campo UDM, adicione um (?s)
à expressão regular. Por exemplo, substitua /.*allUDM.*/
por
/(?s).*allUDM.*/
.
- Use o modificador
nocase
depois das strings para indicar que a pesquisa
deve ignorar a capitalização.
Tipos de dados de parâmetros
STRING
, STRING
Tipos de expressão de parâmetro
ANY
, ANY
Tipo de retorno
BOOL
Amostras de código
Exemplo 1
// Equivalent to $e.principal.hostname = /google/
re.regex($e.principal.hostname, "google")
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
Última atualização 2025-07-29 UTC.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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\")"]]