Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
re.regex
Vous pouvez définir la correspondance d'expressions régulières dans YARA-L 2.0 à l'aide de l'une des syntaxes suivantes :
Utilisation de la syntaxe YARA-L : concerne les événements.
Voici une représentation générique de cette syntaxe :
$e.field = /regex/
En utilisant la syntaxe YARA-L : en tant que fonction prenant les paramètres suivants :
- Champ auquel l'expression régulière est appliquée.
- Expression régulière spécifiée sous forme de chaîne.
Voici une représentation générique de cette syntaxe :
re.regex($e.field, `regex`)
Description
Cette fonction renvoie true
si la chaîne contient une sous-chaîne qui correspond à l'expression régulière fournie. Il n'est pas nécessaire d'ajouter .*
au début ou à la fin de l'expression régulière.
Remarques
- Pour faire correspondre la chaîne exacte ou uniquement un préfixe ou un suffixe, incluez les caractères d'ancrage
^
(début) et $
(fin) dans l'expression régulière.
Par exemple, /^full$/
correspond exactement à "full"
, tandis que /full/
peut correspondre à "fullest"
, "lawfull"
et "joyfully"
.
- Si le champ UDM inclut des caractères de retour à la ligne,
regexp
ne correspond qu'à la première ligne du champ UDM. Pour forcer la correspondance complète des champs UDM, ajoutez (?s)
à l'expression régulière. Par exemple, remplacez /.*allUDM.*/
par /(?s).*allUDM.*/
.
- Vous pouvez utiliser le modificateur
nocase
après les chaînes pour indiquer que la recherche doit ignorer la casse.
Types de données des paramètres
STRING
– STRING
Types d'expressions de paramètre
ANY
– ANY
Type renvoyé
BOOL
Exemples de code
Exemple 1
// Equivalent to $e.principal.hostname = /google/
re.regex($e.principal.hostname, "google")
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/29 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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\")"]]