컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
re.capture
re.capture(stringText, regex)
설명
인수에 제공된 정규 표현식 패턴을 사용하여 문자열에서 데이터를 캡처(추출)합니다.
이 함수에는 두 개의 인수가 사용됩니다.
stringText
: 검색할 원래 문자열입니다.
regex
: 검색할 패턴을 나타내는 정규 표현식입니다.
정규 표현식은 0 또는 1 캡처 그룹을 괄호로 포함할 수 있습니다. 정규 표현식에 0 캡처 그룹이 포함된 경우 함수가 첫 번째 전체 일치 하위 문자열을 반환합니다. 정규 표현식에 1 캡처 그룹이 포함된 경우 캡처 그룹의 첫 번째 일치 하위 문자열을 반환합니다. 캡처 그룹을 2개 이상 정의하면 컴파일 오류가 반환됩니다.
매개변수 데이터 유형
STRING
, STRING
반환 유형
STRING
코드 샘플
예 1
이 예시에서 $e.principal.hostname
에 'aaa1bbaa2'가 포함되면 함수가 첫 번째 인스턴스를 반환하므로 다음이 True입니다. 이 예시에는 캡처 그룹이 없습니다.
"aaa1" = re.capture($e.principal.hostname, "a+[1-9]")
예 2
이 예시에서는 이메일에서 @ 기호 다음에 있는 모든 내용을 캡처합니다. $e.network.email.from
필드가 test@google.com
이면 예시에서 google.com
을 반환합니다. 다음 예시에는 캡처 그룹 하나가 포함되어 있습니다.
"google.com" = re.capture($e.network.email.from , "@(.*)")
예 3
정규 표현식이 텍스트의 하위 문자열과 일치하지 않으면 함수는 빈 문자열을 반환합니다. 빈 문자열을 제외하여 일치하는 항목이 없는 이벤트를 생략할 수 있습니다. 이는 re.capture()
를 불일치로 사용하는 경우에 특히 중요합니다.
// Exclude the empty string to omit events where no match occurs.
"" != re.capture($e.network.email.from , "@(.*)")
// Exclude a specific string with an inequality.
"google.com" != re.capture($e.network.email.from , "@(.*)")
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-29(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-29(UTC)"],[[["\u003cp\u003e\u003ccode\u003ere.capture\u003c/code\u003e extracts data from a string based on a provided regular expression pattern, supporting up to one capture group.\u003c/p\u003e\n"],["\u003cp\u003eThe function returns the entire matching substring if no capture groups are defined in the regular expression or the substring within the capture group if one is defined.\u003c/p\u003e\n"],["\u003cp\u003eIf the regular expression doesn't find a match, \u003ccode\u003ere.capture\u003c/code\u003e returns an empty string, allowing for the exclusion of non-matching events using inequality operators.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ere.capture\u003c/code\u003e takes two arguments, the \u003ccode\u003estringText\u003c/code\u003e, and the \u003ccode\u003eregex\u003c/code\u003e, and both of these arguments must be of the type \u003ccode\u003eSTRING\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ere.capture\u003c/code\u003e is supported in both \u003ccode\u003eRules\u003c/code\u003e and \u003ccode\u003eSearch\u003c/code\u003e environments, as specified in the supported in section.\u003c/p\u003e\n"]]],[],null,["### re.capture\n\nSupported in: \n[Rules](/chronicle/docs/detection/default-rules) [Search](/chronicle/docs/investigation/udm-search) \n\n re.capture(stringText, regex)\n\n#### Description\n\nCaptures (extracts) data from a string using the regular expression pattern\nprovided in the argument.\n\nThis function takes two arguments:\n\n- `stringText`: the original string to search.\n- `regex`: the regular expression indicating the pattern to search for.\n\nThe regular expression can contain 0 or 1 capture groups in parentheses. If the\nregular expression contains 0 capture groups, the function returns the first\nentire matching substring. If the regular expression contains 1 capture group,\nit returns the first matching substring for the capture group. Defining two or\nmore capture groups returns a compiler error.\n\n#### Param data types\n\n`STRING`, `STRING`\n\n#### Return type\n\n`STRING`\n\n#### Code samples\n\n##### Example 1\n\nIn this example, if `$e.principal.hostname` contains \"aaa1bbaa2\" the following would be true, because the function\nreturns the first instance. This example has no capture groups. \n\n \"aaa1\" = re.capture($e.principal.hostname, \"a+[1-9]\")\n\n##### Example 2\n\nThis example captures everything after the @ symbol in an email. If the\n`$e.network.email.from` field is `test@google.com`, the example returns\n`google.com`. The following example contains one capture group. \n\n \"google.com\" = re.capture($e.network.email.from , \"@(.*)\")\n\n##### Example 3\n\nIf the regular expression does not match any substring in the text, the\nfunction returns an empty string. You can omit events where no match occurs\nby excluding the empty string, which is especially important when you are\nusing `re.capture()` with an inequality: \n\n // Exclude the empty string to omit events where no match occurs.\n \"\" != re.capture($e.network.email.from , \"@(.*)\")\n\n // Exclude a specific string with an inequality.\n \"google.com\" != re.capture($e.network.email.from , \"@(.*)\")"]]