mirror of
https://github.com/golang/go
synced 2024-11-18 13:44:48 -07:00
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>
This commit is contained in:
parent
143f3fd0ee
commit
226aaf4267
@ -146,3 +146,25 @@ func ExampleRegexp_SubexpNames() {
|
|||||||
// ${last} ${first}
|
// ${last} ${first}
|
||||||
// Turing Alan
|
// 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]
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user