aboutsummaryrefslogtreecommitdiff
path: root/src/regexp
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2018-07-13 10:28:56 -0400
committerRuss Cox <rsc@golang.org>2018-07-13 18:52:46 +0000
commitf50448f531887a5fefc95fe29735e71d3542ef2c (patch)
tree9f6ec86f2b05e6e946ecc33cdf70bc10a94fb375 /src/regexp
parent204c618f0a0b175d840bfeb50cb5356deb165f51 (diff)
downloadgo-f50448f531887a5fefc95fe29735e71d3542ef2c.tar.gz
go-f50448f531887a5fefc95fe29735e71d3542ef2c.zip
regexp: reword Match documentation to be more like Find
Before: // Find returns a slice holding the text of the leftmost match in b of the regular expression. // Match checks whether a textual regular expression matches a byte slice. After: // Match reports whether the byte slice b contains any match of the regular expression re. The use of different wording for Find and Match always makes me think that Match required the entire string to match while Find clearly allows a substring to match. This CL makes the Match wording correspond more closely to Find, to try to avoid that confusion. Change-Id: I97fb82d5080d3246ee5cf52abf28d2a2296a5039 Reviewed-on: https://go-review.googlesource.com/123736 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/regexp')
-rw-r--r--src/regexp/regexp.go32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/regexp/regexp.go b/src/regexp/regexp.go
index 811187175d..61ed9c5059 100644
--- a/src/regexp/regexp.go
+++ b/src/regexp/regexp.go
@@ -429,25 +429,27 @@ func (re *Regexp) LiteralPrefix() (prefix string, complete bool) {
return re.prefix, re.prefixComplete
}
-// MatchReader reports whether the Regexp matches the text read by the
-// RuneReader.
+// MatchReader reports whether the text returned by the RuneReader
+// contains any match of the regular expression re.
func (re *Regexp) MatchReader(r io.RuneReader) bool {
return re.doMatch(r, nil, "")
}
-// MatchString reports whether the Regexp matches the string s.
+// MatchString reports whether the string s
+// contains any match of the regular expression re.
func (re *Regexp) MatchString(s string) bool {
return re.doMatch(nil, nil, s)
}
-// Match reports whether the Regexp matches the byte slice b.
+// Match reports whether the byte slice b
+// contains any match of the regular expression re.
func (re *Regexp) Match(b []byte) bool {
return re.doMatch(nil, b, "")
}
-// MatchReader checks whether a textual regular expression matches the text
-// read by the RuneReader. More complicated queries need to use Compile and
-// the full Regexp interface.
+// MatchReader reports whether the text returned by the RuneReader
+// contains any match of the regular expression pattern.
+// More complicated queries need to use Compile and the full Regexp interface.
func MatchReader(pattern string, r io.RuneReader) (matched bool, err error) {
re, err := Compile(pattern)
if err != nil {
@@ -456,9 +458,9 @@ func MatchReader(pattern string, r io.RuneReader) (matched bool, err error) {
return re.MatchReader(r), nil
}
-// MatchString checks whether a textual regular expression
-// matches a string. More complicated queries need
-// to use Compile and the full Regexp interface.
+// MatchString reports whether the string s
+// contains any match of the regular expression pattern.
+// More complicated queries need to use Compile and the full Regexp interface.
func MatchString(pattern string, s string) (matched bool, err error) {
re, err := Compile(pattern)
if err != nil {
@@ -467,9 +469,9 @@ func MatchString(pattern string, s string) (matched bool, err error) {
return re.MatchString(s), nil
}
-// Match checks whether a textual regular expression
-// matches a byte slice. More complicated queries need
-// to use Compile and the full Regexp interface.
+// MatchString reports whether the byte slice b
+// contains any match of the regular expression pattern.
+// More complicated queries need to use Compile and the full Regexp interface.
func Match(pattern string, b []byte) (matched bool, err error) {
re, err := Compile(pattern)
if err != nil {
@@ -675,7 +677,9 @@ func (re *Regexp) pad(a []int) []int {
return a
}
-// Find matches in slice b if b is non-nil, otherwise find matches in string s.
+// allMatches calls deliver at most n times
+// with the location of successive matches in the input text.
+// The input text is b if non-nil, otherwise s.
func (re *Regexp) allMatches(s string, b []byte, n int, deliver func([]int)) {
var end int
if b == nil {