OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package regexp implements regular expression search. | 5 // Package regexp implements regular expression search. |
6 // | 6 // |
7 // The syntax of the regular expressions accepted is the same | 7 // The syntax of the regular expressions accepted is the same |
8 // general syntax used by Perl, Python, and other languages. | 8 // general syntax used by Perl, Python, and other languages. |
9 // More precisely, it is the syntax accepted by RE2 and described at | 9 // More precisely, it is the syntax accepted by RE2 and described at |
10 // http://code.google.com/p/re2/wiki/Syntax, except for \C. | 10 // http://code.google.com/p/re2/wiki/Syntax, except for \C. |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 | 390 |
391 // Match returns whether the Regexp matches the byte slice b. | 391 // Match returns whether the Regexp matches the byte slice b. |
392 // The return value is a boolean: true for match, false for no match. | 392 // The return value is a boolean: true for match, false for no match. |
393 func (re *Regexp) Match(b []byte) bool { | 393 func (re *Regexp) Match(b []byte) bool { |
394 return re.doExecute(nil, b, "", 0, 0) != nil | 394 return re.doExecute(nil, b, "", 0, 0) != nil |
395 } | 395 } |
396 | 396 |
397 // MatchReader checks whether a textual regular expression matches the text | 397 // MatchReader checks whether a textual regular expression matches the text |
398 // read by the RuneReader. More complicated queries need to use Compile and | 398 // read by the RuneReader. More complicated queries need to use Compile and |
399 // the full Regexp interface. | 399 // the full Regexp interface. |
400 func MatchReader(pattern string, r io.RuneReader) (matched bool, error error) { | 400 func MatchReader(pattern string, r io.RuneReader) (matched bool, err error) { |
401 re, err := Compile(pattern) | 401 re, err := Compile(pattern) |
402 if err != nil { | 402 if err != nil { |
403 return false, err | 403 return false, err |
404 } | 404 } |
405 return re.MatchReader(r), nil | 405 return re.MatchReader(r), nil |
406 } | 406 } |
407 | 407 |
408 // MatchString checks whether a textual regular expression | 408 // MatchString checks whether a textual regular expression |
409 // matches a string. More complicated queries need | 409 // matches a string. More complicated queries need |
410 // to use Compile and the full Regexp interface. | 410 // to use Compile and the full Regexp interface. |
411 func MatchString(pattern string, s string) (matched bool, error error) { | 411 func MatchString(pattern string, s string) (matched bool, err error) { |
412 re, err := Compile(pattern) | 412 re, err := Compile(pattern) |
413 if err != nil { | 413 if err != nil { |
414 return false, err | 414 return false, err |
415 } | 415 } |
416 return re.MatchString(s), nil | 416 return re.MatchString(s), nil |
417 } | 417 } |
418 | 418 |
419 // Match checks whether a textual regular expression | 419 // Match checks whether a textual regular expression |
420 // matches a byte slice. More complicated queries need | 420 // matches a byte slice. More complicated queries need |
421 // to use Compile and the full Regexp interface. | 421 // to use Compile and the full Regexp interface. |
422 func Match(pattern string, b []byte) (matched bool, error error) { | 422 func Match(pattern string, b []byte) (matched bool, err error) { |
423 re, err := Compile(pattern) | 423 re, err := Compile(pattern) |
424 if err != nil { | 424 if err != nil { |
425 return false, err | 425 return false, err |
426 } | 426 } |
427 return re.Match(b), nil | 427 return re.Match(b), nil |
428 } | 428 } |
429 | 429 |
430 // ReplaceAllString returns a copy of src, replacing matches of the Regexp | 430 // ReplaceAllString returns a copy of src, replacing matches of the Regexp |
431 // with the replacement string repl. Inside repl, $ signs are interpreted as | 431 // with the replacement string repl. Inside repl, $ signs are interpreted as |
432 // in Expand, so for instance $1 represents the text of the first submatch. | 432 // in Expand, so for instance $1 represents the text of the first submatch. |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 } | 1100 } |
1101 beg = match[1] | 1101 beg = match[1] |
1102 } | 1102 } |
1103 | 1103 |
1104 if end != len(s) { | 1104 if end != len(s) { |
1105 strings = append(strings, s[beg:]) | 1105 strings = append(strings, s[beg:]) |
1106 } | 1106 } |
1107 | 1107 |
1108 return strings | 1108 return strings |
1109 } | 1109 } |
OLD | NEW |