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

Method FindString

regex.go:324–331  ·  view source on GitHub ↗

FindString returns a string holding the text of the leftmost match in s. Returns empty string if no match is found. Example: re := coregex.MustCompile(`\d+`) match := re.FindString("age: 42") println(match) // "42"

(s string)

Source from the content-addressed store, hash-verified

322// match := re.FindString("age: 42")
323// println(match) // "42"
324func (r *Regex) FindString(s string) string {
325 b := stringToBytes(s)
326 start, end, found := r.engine.FindIndices(b)
327 if !found {
328 return ""
329 }
330 return s[start:end] // Return substring of original string - no allocation for input
331}
332
333// FindIndex returns a two-element slice of integers defining the location of
334// the leftmost match in b. The match is at b[loc[0]:loc[1]].

Callers 15

TestCompilePOSIXFunction · 0.80
TestCopyFunction · 0.80
TestCopyWithLongestFunction · 0.80
TestStdlibCompat_LongestFunction · 0.80
FuzzFindStdlibFunction · 0.80
FuzzQuoteMetaStdlibFunction · 0.80
TestWordBoundaryVsStdlibFunction · 0.80
TestGoAWK_MatchPatternFunction · 0.80
ExampleRegex_FindStringFunction · 0.80
TestFindFunction · 0.80

Calls 2

stringToBytesFunction · 0.85
FindIndicesMethod · 0.80

Tested by 15

TestCompilePOSIXFunction · 0.64
TestCopyFunction · 0.64
TestCopyWithLongestFunction · 0.64
TestStdlibCompat_LongestFunction · 0.64
FuzzFindStdlibFunction · 0.64
FuzzQuoteMetaStdlibFunction · 0.64
TestWordBoundaryVsStdlibFunction · 0.64
TestGoAWK_MatchPatternFunction · 0.64
ExampleRegex_FindStringFunction · 0.64
TestFindFunction · 0.64