Print the function being executed
details --------- - it is difficult to track which fmt.Println statement is printing which output
This commit is contained in:
parent
43825687bb
commit
861aafbd29
@ -23,46 +23,46 @@ func main() {
|
|||||||
|
|
||||||
// Many methods are available on these structs. Here's
|
// Many methods are available on these structs. Here's
|
||||||
// a match test like we saw earlier.
|
// a match test like we saw earlier.
|
||||||
fmt.Println(r.MatchString("peach"))
|
fmt.Println("MatchString", r.MatchString("peach"))
|
||||||
|
|
||||||
// This finds the match for the regexp.
|
// This finds the match for the regexp.
|
||||||
fmt.Println(r.FindString("peach punch"))
|
fmt.Println("FindString", r.FindString("peach punch"))
|
||||||
|
|
||||||
// This also finds the first match but returns the
|
// This also finds the first match but returns the
|
||||||
// start and end indexes for the match instead of the
|
// start and end indexes for the match instead of the
|
||||||
// matching text.
|
// matching text.
|
||||||
fmt.Println(r.FindStringIndex("peach punch"))
|
fmt.Println("FindStringIndex", r.FindStringIndex("peach punch"))
|
||||||
|
|
||||||
// The `Submatch` variants include information about
|
// The `Submatch` variants include information about
|
||||||
// both the whole-pattern matches and the submatches
|
// both the whole-pattern matches and the submatches
|
||||||
// within those matches. For example this will return
|
// within those matches. For example this will return
|
||||||
// information for both `p([a-z]+)ch` and `([a-z]+)`.
|
// information for both `p([a-z]+)ch` and `([a-z]+)`.
|
||||||
fmt.Println(r.FindStringSubmatch("peach punch"))
|
fmt.Println("FindStringSubmatch", r.FindStringSubmatch("peach punch"))
|
||||||
|
|
||||||
// Similarly this will return information about the
|
// Similarly this will return information about the
|
||||||
// indexes of matches and submatches.
|
// indexes of matches and submatches.
|
||||||
fmt.Println(r.FindStringSubmatchIndex("peach punch"))
|
fmt.Println("FindStringSubmatchIndex", r.FindStringSubmatchIndex("peach punch"))
|
||||||
|
|
||||||
// The `All` variants of these functions apply to all
|
// The `All` variants of these functions apply to all
|
||||||
// matches in the input, not just the first. For
|
// matches in the input, not just the first. For
|
||||||
// example to find all matches for a regexp.
|
// example to find all matches for a regexp.
|
||||||
fmt.Println(r.FindAllString("peach punch pinch", -1))
|
fmt.Println("FindAllString", r.FindAllString("peach punch pinch", -1))
|
||||||
|
|
||||||
// These `All` variants are available for the other
|
// These `All` variants are available for the other
|
||||||
// functions we saw above as well.
|
// functions we saw above as well.
|
||||||
fmt.Println(r.FindAllStringSubmatchIndex(
|
fmt.Println("FindAllStringSubmatchIndex", r.FindAllStringSubmatchIndex(
|
||||||
"peach punch pinch", -1))
|
"peach punch pinch", -1))
|
||||||
|
|
||||||
// Providing a non-negative integer as the second
|
// Providing a non-negative integer as the second
|
||||||
// argument to these functions will limit the number
|
// argument to these functions will limit the number
|
||||||
// of matches.
|
// of matches.
|
||||||
fmt.Println(r.FindAllString("peach punch pinch", 2))
|
fmt.Println("FindAllString", r.FindAllString("peach punch pinch", 2))
|
||||||
|
|
||||||
// Our examples above had string arguments and used
|
// Our examples above had string arguments and used
|
||||||
// names like `MatchString`. We can also provide
|
// names like `MatchString`. We can also provide
|
||||||
// `[]byte` arguments and drop `String` from the
|
// `[]byte` arguments and drop `String` from the
|
||||||
// function name.
|
// function name.
|
||||||
fmt.Println(r.Match([]byte("peach")))
|
fmt.Println("Match", r.Match([]byte("peach")))
|
||||||
|
|
||||||
// When creating constants with regular expressions
|
// When creating constants with regular expressions
|
||||||
// you can use the `MustCompile` variation of
|
// you can use the `MustCompile` variation of
|
||||||
@ -73,7 +73,7 @@ func main() {
|
|||||||
|
|
||||||
// The `regexp` package can also be used to replace
|
// The `regexp` package can also be used to replace
|
||||||
// subsets of strings with other values.
|
// subsets of strings with other values.
|
||||||
fmt.Println(r.ReplaceAllString("a peach", "<fruit>"))
|
fmt.Println("ReplaceAllString", r.ReplaceAllString("a peach", "<fruit>"))
|
||||||
|
|
||||||
// The `Func` variant allows you to transform matched
|
// The `Func` variant allows you to transform matched
|
||||||
// text with a given function.
|
// text with a given function.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user