Search returns lines within a sheet's Text that match the search regex
(reg *regexp.Regexp)
| 7 | |
| 8 | // Search returns lines within a sheet's Text that match the search regex |
| 9 | func (s *Sheet) Search(reg *regexp.Regexp) string { |
| 10 | |
| 11 | // record matches |
| 12 | var matches []string |
| 13 | |
| 14 | // search through the cheatsheet's text line by line |
| 15 | for _, line := range strings.Split(s.Text, "\n\n") { |
| 16 | |
| 17 | // save matching lines |
| 18 | if reg.MatchString(line) { |
| 19 | matches = append(matches, line) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | // Join matches with the same delimiter used for splitting |
| 24 | return strings.Join(matches, "\n\n") |
| 25 | } |
no outgoing calls