MCPcopy Create free account
hub / github.com/coregx/coregex / ExampleRegex_FindSubmatch

Function ExampleRegex_FindSubmatch

example_test.go:88–102  ·  view source on GitHub ↗

ExampleRegex_FindSubmatch demonstrates capture group extraction.

()

Source from the content-addressed store, hash-verified

86
87// ExampleRegex_FindSubmatch demonstrates capture group extraction.
88func 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.
105func ExampleRegex_FindStringSubmatch() {

Callers

nothing calls this directly

Calls 2

MustCompileFunction · 0.92
FindSubmatchMethod · 0.45

Tested by

no test coverage detected