diff --git a/regex/matching.go b/regex/matching.go index 0f4023b..f47aca4 100644 --- a/regex/matching.go +++ b/regex/matching.go @@ -153,8 +153,9 @@ func (regex Reg) FindString(str string) string { // FindAllString is the 'all' version of FindString. // It returns a slice of strings containing the text of all matches of // the regex in the given string. -func FindAllString(regex Reg, str []string) []string { +func (regex Reg) FindAllString(str string) []string { return []string{} + // matches := FindAllMatches, str string) } // FindNthMatch finds the 'n'th match of the regex represented by the given start-state, with @@ -179,9 +180,18 @@ func FindNthMatch(regex Reg, str string, n int) (Match, error) { return nil, fmt.Errorf("invalid match index - too few matches found") } -// FindAllMatches tries to find all matches of the regex represented by given start-state, with -// the given string -func FindAllMatches(regex Reg, str string) []Match { +// FindAll returns a slice containing all the 0-groups of the regex in the given string. +// A 0-group represents the match without any submatches. +func (regex Reg) FindAll(str string) []Group { + indices := regex.FindAllSubmatch(str) + zeroGroups := funcMap(indices, func(m Match) Group { + return m[0] + }) + return zeroGroups +} + +// FindAllSubmatch returns a slice of matches in the given string. +func (regex Reg) FindAllSubmatch(str string) []Match { idx := 0 str_runes := []rune(str) var matchFound bool @@ -196,6 +206,7 @@ func FindAllMatches(regex Reg, str string) []Match { if len(indices) > 0 { return pruneIndices(indices) } + return indices }