使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
re.regex
您可以在 YARA-L 2.0 中使用以下任一语法定义正则表达式匹配:
说明
如果字符串包含与所提供正则表达式匹配的子字符串,则此函数返回 true
。无需在正则表达式的开头或结尾添加 .*
。
备注
- 如需匹配确切的字符串,或仅匹配前缀或后缀,请在正则表达式中添加
^
(开头)和 $
(结尾)定位字符。例如,/^full$/
与 "full"
完全匹配,而 /full/
可以与 "fullest"
、"lawfull"
和 "joyfully"
匹配。
- 如果 UDM 字段包含换行符,则
regexp
仅匹配 UDM 字段的第一行。如需强制执行完整的 UDM 字段匹配,请将 (?s)
添加到正则表达式。例如,将 /.*allUDM.*/
替换为 /(?s).*allUDM.*/
。
- 您可以在字符串之后使用
nocase
修饰符,以指示搜索应忽略大小写。
形参数据类型
STRING
,STRING
参数表达式类型
ANY
,ANY
返回类型
BOOL
代码示例
示例 1
// Equivalent to $e.principal.hostname = /google/
re.regex($e.principal.hostname, "google")
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-29。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-29。"],[[["\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\")"]]