Add regexp
This commit is contained in:
parent
774faa3ea4
commit
2b310f1f7d
6
main.go
6
main.go
@ -24,7 +24,8 @@ package main
|
|||||||
// import "git.sangeeth.dev/gobyexample/recovering"
|
// import "git.sangeeth.dev/gobyexample/recovering"
|
||||||
// import "git.sangeeth.dev/gobyexample/stringfuncs"
|
// import "git.sangeeth.dev/gobyexample/stringfuncs"
|
||||||
// import "git.sangeeth.dev/gobyexample/formatting"
|
// import "git.sangeeth.dev/gobyexample/formatting"
|
||||||
import "git.sangeeth.dev/gobyexample/templates"
|
// import "git.sangeeth.dev/gobyexample/templates"
|
||||||
|
import "git.sangeeth.dev/gobyexample/regex"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// runes.Runes()
|
// runes.Runes()
|
||||||
@ -51,5 +52,6 @@ func main() {
|
|||||||
// recovering.Recover()
|
// recovering.Recover()
|
||||||
// stringfuncs.StringFuncs()
|
// stringfuncs.StringFuncs()
|
||||||
// formatting.Formatting()
|
// formatting.Formatting()
|
||||||
templates.Templates()
|
// templates.Templates()
|
||||||
|
regex.Regex()
|
||||||
}
|
}
|
||||||
|
25
regex/regex.go
Normal file
25
regex/regex.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package regex
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var r = regexp.MustCompile("p([a-z]+)ch")
|
||||||
|
var f = fmt.Println
|
||||||
|
|
||||||
|
func Regex() {
|
||||||
|
matches, _ := regexp.MatchString("p([a-z]+)ch", "peach")
|
||||||
|
f("regexp.MatchString =>", matches)
|
||||||
|
|
||||||
|
f("r.MatchString() =>", r.MatchString("peach"))
|
||||||
|
f("r.FindString() =>", r.FindString("peach poach pouch"))
|
||||||
|
f("r.FindAllString() =>", r.FindAllString("peach poach pouch", -1))
|
||||||
|
f("r.FindStringIndex() =>", r.FindStringIndex("peach poach pouch"))
|
||||||
|
f("r.FindAllStringIndex() =>", r.FindAllStringIndex("peach poach pouch", -1))
|
||||||
|
f("r.FindStringSubmatch() =>", r.FindStringSubmatch("peach poach pouch"))
|
||||||
|
f("r.FindAllStringSubmatch() =>", r.FindAllStringSubmatch("peach poach pouch", -1))
|
||||||
|
f("r.ReplaceAllString() =>", r.ReplaceAllString("peach poach pouch", "<fruit>"))
|
||||||
|
f("r.ReplaceAllStringFunc() =>", r.ReplaceAllStringFunc("peachy peter poached a pouch", func(sub string) string { return strings.ToUpper(sub) }))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user