diff options
author | Seth Hoenig <seth.a.hoenig@gmail.com> | 2015-09-17 23:26:39 -0500 |
---|---|---|
committer | Andrew Gerrand <adg@golang.org> | 2015-09-23 03:29:32 +0000 |
commit | 226aaf4267316cab7530b0dabe24e6c20787fab4 (patch) | |
tree | 75e2d6f3f5e25377269dc9e9438446407805725a | |
parent | 143f3fd0ee71e6b015029b6792bc873b1013a8d4 (diff) | |
download | go-git-226aaf4267316cab7530b0dabe24e6c20787fab4.tar.gz |
regexp: add runnable example to regex.Split
The existing comment for regex.Split contains a plain text example,
while many of the other regex functions have runnable examples. This
change provides a runnable example for Split.
Change-Id: I5373f57f532fe843d7d0adcf4b513061ec797047
Reviewed-on: https://go-review.googlesource.com/14737
Reviewed-by: Andrew Gerrand <adg@golang.org>
Run-TryBot: Andrew Gerrand <adg@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r-- | src/regexp/example_test.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/regexp/example_test.go b/src/regexp/example_test.go index a4e0da8eaa..d05e87b0db 100644 --- a/src/regexp/example_test.go +++ b/src/regexp/example_test.go @@ -146,3 +146,25 @@ func ExampleRegexp_SubexpNames() { // ${last} ${first} // Turing Alan } + +func ExampleRegexp_Split() { + a := regexp.MustCompile("a") + fmt.Println(a.Split("banana", -1)) + fmt.Println(a.Split("banana", 0)) + fmt.Println(a.Split("banana", 1)) + fmt.Println(a.Split("banana", 2)) + zp := regexp.MustCompile("z+") + fmt.Println(zp.Split("pizza", -1)) + fmt.Println(zp.Split("pizza", 0)) + fmt.Println(zp.Split("pizza", 1)) + fmt.Println(zp.Split("pizza", 2)) + // Output: + // [b n n ] + // [] + // [banana] + // [b nana] + // [pi a] + // [] + // [pizza] + // [pi a] +} |