Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(618)

Unified Diff: src/pkg/regexp/example_test.go

Issue 6846045: code review 6846045: regexp: add simple package-level example (Closed)
Patch Set: diff -r d9896259d8e5 https://code.google.com/p/go Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/regexp/example_test.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/pkg/regexp/example_test.go
@@ -0,0 +1,22 @@
+package regexp_test
+
+import (
+ "fmt"
+ "regexp"
+)
+
+func Example() {
+ // Compile the expression once, usually at init time.
+ // Use raw strings to avoid having to quote the backslashes.
+ var validID = regexp.MustCompile(`^[a-z]+\[[0-9]+\]$`)
+
+ fmt.Println(validID.MatchString("adam[23]"))
+ fmt.Println(validID.MatchString("eve[7]"))
+ fmt.Println(validID.MatchString("Job[48]"))
+ fmt.Println(validID.MatchString("snakey"))
+ // Output:
+ // true
+ // true
+ // false
+ // false
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b