2 Commits

2 changed files with 35 additions and 3 deletions

32
regex/example_test.go Normal file
View File

@@ -0,0 +1,32 @@
package regex_test
import (
"fmt"
"gitea.twomorecents.org/Rockingcool/kleingrep/regex"
)
func ExampleReg_Find() {
regexStr := "b|a"
regexComp := regex.MustCompile(regexStr)
match, _ := regexComp.Find("banana")
fmt.Println(match.String())
// Output: 0 1
}
func ExampleReg_FindAll() {
regexStr := "b|a"
regexComp := regex.MustCompile(regexStr)
matches := regexComp.FindAll("banana")
for _, group := range matches {
fmt.Println(group.String())
}
// Output: 0 1
// 1 2
// 3 4
// 5 6
}

View File

@@ -40,15 +40,15 @@ func (m Match) String() string {
for i, g := range m {
if g.IsValid() {
toRet += fmt.Sprintf("Group %d\n", i)
toRet += g.toString()
toRet += g.String()
toRet += "\n"
}
}
return toRet
}
// Converts the Group into a string representation:
func (idx Group) toString() string {
// String converts the Group into a string representation.
func (idx Group) String() string {
return fmt.Sprintf("%d\t%d", idx.StartIdx, idx.EndIdx)
}