ExampleRegex_FindSubmatch demonstrates capture group extraction.
()
| 86 | |
| 87 | // ExampleRegex_FindSubmatch demonstrates capture group extraction. |
| 88 | func ExampleRegex_FindSubmatch() { |
| 89 | re := coregex.MustCompile(`(\w+)@(\w+)\.(\w+)`) |
| 90 | match := re.FindSubmatch([]byte("Contact: user@example.com")) |
| 91 | if match != nil { |
| 92 | fmt.Println("Full match:", string(match[0])) |
| 93 | fmt.Println("User:", string(match[1])) |
| 94 | fmt.Println("Domain:", string(match[2])) |
| 95 | fmt.Println("TLD:", string(match[3])) |
| 96 | } |
| 97 | // Output: |
| 98 | // Full match: user@example.com |
| 99 | // User: user |
| 100 | // Domain: example |
| 101 | // TLD: com |
| 102 | } |
| 103 | |
| 104 | // ExampleRegex_FindStringSubmatch demonstrates capture groups with strings. |
| 105 | func ExampleRegex_FindStringSubmatch() { |
nothing calls this directly
no test coverage detected