Compare commits
2 Commits
2a9ae0b68a
...
6d692d0dfc
Author | SHA1 | Date | |
---|---|---|---|
6d692d0dfc | |||
7c4538a259 |
32
regex/example_test.go
Normal file
32
regex/example_test.go
Normal 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
|
||||
}
|
@@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user