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)
| 322 | // match := re.FindString("age: 42") |
| 323 | // println(match) // "42" |
| 324 | func (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]]. |