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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 n := 2 | 445 n := 2 |
446 if strings.Index(repl, "$") >= 0 { | 446 if strings.Index(repl, "$") >= 0 { |
447 n = 2 * (re.numSubexp + 1) | 447 n = 2 * (re.numSubexp + 1) |
448 } | 448 } |
449 b := re.replaceAll(nil, src, n, func(dst []byte, match []int) []byte { | 449 b := re.replaceAll(nil, src, n, func(dst []byte, match []int) []byte { |
450 return re.expand(dst, repl, nil, src, match) | 450 return re.expand(dst, repl, nil, src, match) |
451 }) | 451 }) |
452 return string(b) | 452 return string(b) |
453 } | 453 } |
454 | 454 |
455 // ReplaceAllStringLiteral returns a copy of src, replacing matches of the Regex
p | 455 // ReplaceAllLiteralString returns a copy of src, replacing matches of the Regex
p |
456 // with the replacement string repl. The replacement repl is substituted direct
ly, | 456 // with the replacement string repl. The replacement repl is substituted direct
ly, |
457 // without using Expand. | 457 // without using Expand. |
458 func (re *Regexp) ReplaceAllLiteralString(src, repl string) string { | 458 func (re *Regexp) ReplaceAllLiteralString(src, repl string) string { |
459 return string(re.replaceAll(nil, src, 2, func(dst []byte, match []int) [
]byte { | 459 return string(re.replaceAll(nil, src, 2, func(dst []byte, match []int) [
]byte { |
460 return append(dst, repl...) | 460 return append(dst, repl...) |
461 })) | 461 })) |
462 } | 462 } |
463 | 463 |
464 // ReplaceAllStringFunc returns a copy of src in which all matches of the | 464 // ReplaceAllStringFunc returns a copy of src in which all matches of the |
465 // Regexp have been replaced by the return value of function repl applied | 465 // Regexp have been replaced by the return value of function repl applied |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 } | 1111 } |
1112 beg = match[1] | 1112 beg = match[1] |
1113 } | 1113 } |
1114 | 1114 |
1115 if end != len(s) { | 1115 if end != len(s) { |
1116 strings = append(strings, s[beg:]) | 1116 strings = append(strings, s[beg:]) |
1117 } | 1117 } |
1118 | 1118 |
1119 return strings | 1119 return strings |
1120 } | 1120 } |
OLD | NEW |