From 861aafbd2900c9e69dc560ab927e662c581d5ee4 Mon Sep 17 00:00:00 2001 From: Suraj Banakar <34534103+vadasambar@users.noreply.github.com> Date: Tue, 15 Oct 2019 20:11:46 +0530 Subject: [PATCH] Print the function being executed details --------- - it is difficult to track which fmt.Println statement is printing which output --- .../regular-expressions.go | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/regular-expressions/regular-expressions.go b/examples/regular-expressions/regular-expressions.go index 52ec06d..c04cc4c 100644 --- a/examples/regular-expressions/regular-expressions.go +++ b/examples/regular-expressions/regular-expressions.go @@ -23,46 +23,46 @@ func main() { // Many methods are available on these structs. Here's // 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. - fmt.Println(r.FindString("peach punch")) + fmt.Println("FindString", r.FindString("peach punch")) // This also finds the first match but returns the // start and end indexes for the match instead of the // matching text. - fmt.Println(r.FindStringIndex("peach punch")) + fmt.Println("FindStringIndex", r.FindStringIndex("peach punch")) // The `Submatch` variants include information about // both the whole-pattern matches and the submatches // within those matches. For example this will return // 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 // 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 // matches in the input, not just the first. For // 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 // functions we saw above as well. - fmt.Println(r.FindAllStringSubmatchIndex( + fmt.Println("FindAllStringSubmatchIndex", r.FindAllStringSubmatchIndex( "peach punch pinch", -1)) // Providing a non-negative integer as the second // argument to these functions will limit the number // 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 // names like `MatchString`. We can also provide // `[]byte` arguments and drop `String` from the // function name. - fmt.Println(r.Match([]byte("peach"))) + fmt.Println("Match", r.Match([]byte("peach"))) // When creating constants with regular expressions // you can use the `MustCompile` variation of @@ -73,7 +73,7 @@ func main() { // The `regexp` package can also be used to replace // subsets of strings with other values. - fmt.Println(r.ReplaceAllString("a peach", "")) + fmt.Println("ReplaceAllString", r.ReplaceAllString("a peach", "")) // The `Func` variant allows you to transform matched // text with a given function.