FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com,

I'd like you to review this change to
https://code.google.com/p/go


Description:
regexp: add simple package-level example

Update issue 4125

Please review this at http://codereview.appspot.com/6846045/

Affected files:
A src/pkg/regexp/example_test.go


Index: src/pkg/regexp/example_test.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/pkg/regexp/example_test.go
@@ -0,0 +1,17 @@
+package regexp_test
+
+import (
+ "fmt"
+ "regexp"
+)
+
+func Example() {
+ // Compile the expression once, usually at init time.
+ var validUser = regexp.MustCompile(`^[A-Za-z0-9-]+$`)
+
+ fmt.Println(validUser.MatchString("ken"))
+ fmt.Println(validUser.Match([]byte("bang!")))
+ // Output:
+ // true
+ // false
+}

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedNov 13, '12 at 11:53a
activeNov 14, '12 at 9:43a
posts6
users2
websitegolang.org

2 users in discussion

Adg: 4 posts R: 2 posts

People

Translate

site design / logo © 2022 Grokbase