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

Method FindStringIndex

regex.go:360–366  ·  view source on GitHub ↗

FindStringIndex returns a two-element slice of integers defining the location of the leftmost match in s. The match is at s[loc[0]:loc[1]]. Returns nil if no match is found. Example: re := coregex.MustCompile(`\d+`) loc := re.FindStringIndex("age: 42") println(loc[0], loc[1]) // 5, 7

(s string)

Source from the content-addressed store, hash-verified

358// loc := re.FindStringIndex("age: 42")
359// println(loc[0], loc[1]) // 5, 7
360func (r *Regex) FindStringIndex(s string) []int {
361 start, end, found := r.engine.FindIndices(stringToBytes(s))
362 if !found {
363 return nil
364 }
365 return []int{start, end}
366}
367
368// FindAll returns a slice of all successive matches of the pattern in b.
369// If n > 0, it returns at most n matches. If n <= 0, it returns all matches.

Callers 15

FindReaderIndexMethod · 0.95
FuzzFindStdlibFunction · 0.80
TestWordBoundaryFunction · 0.80
TestNoWordBoundaryFunction · 0.80
TestWordBoundaryVsStdlibFunction · 0.80
TestGoAWK_MatchPatternFunction · 0.80
BenchmarkGoAWK_MatchFunction · 0.80
BenchmarkGoAWK_LongestFunction · 0.80
TestFindIndexFunction · 0.80

Calls 2

stringToBytesFunction · 0.85
FindIndicesMethod · 0.80

Tested by 15

FuzzFindStdlibFunction · 0.64
TestWordBoundaryFunction · 0.64
TestNoWordBoundaryFunction · 0.64
TestWordBoundaryVsStdlibFunction · 0.64
TestGoAWK_MatchPatternFunction · 0.64
BenchmarkGoAWK_MatchFunction · 0.64
BenchmarkGoAWK_LongestFunction · 0.64
TestFindIndexFunction · 0.64
TestLazyDFAVsStdlibFunction · 0.64