Add partial prefixes in some places to regular-expressions

See #394 for details.

This closes #288 by providing a lighter-weight approach.
This commit is contained in:
Eli Bendersky
2021-09-10 05:56:40 -07:00
parent 2570a9c136
commit 4de485a514
4 changed files with 18 additions and 18 deletions

View File

@@ -31,7 +31,7 @@ func main() {
// This also finds the first match but returns the
// start and end indexes for the match instead of the
// matching text.
fmt.Println(r.FindStringIndex("peach punch"))
fmt.Println("idx:", r.FindStringIndex("peach punch"))
// The `Submatch` variants include information about
// both the whole-pattern matches and the submatches
@@ -50,7 +50,7 @@ func main() {
// These `All` variants are available for the other
// functions we saw above as well.
fmt.Println(r.FindAllStringSubmatchIndex(
fmt.Println("all:", r.FindAllStringSubmatchIndex(
"peach punch pinch", -1))
// Providing a non-negative integer as the second
@@ -70,7 +70,7 @@ func main() {
// returning an error, which makes it safer to use for
// global variables.
r = regexp.MustCompile("p([a-z]+)ch")
fmt.Println(r)
fmt.Println("regexp:", r)
// The `regexp` package can also be used to replace
// subsets of strings with other values.

View File

@@ -1,2 +1,2 @@
c0dd720036ac70269ce233bf47c5d6aefd43161f
LEKGY_d3Nu_P
5c3bcf9f8c61fc074143f766c4517e445a6d9b0f
htCqJrLdh9Q

View File

@@ -1,15 +1,15 @@
$ go run regular-expressions.go
$ go run regular-expressions.go
true
true
peach
[0 5]
idx: [0 5]
[peach ea]
[0 5 1 3]
[peach punch pinch]
[[0 5 1 3] [6 11 7 9] [12 17 13 15]]
all: [[0 5 1 3] [6 11 7 9] [12 17 13 15]]
[peach punch]
true
p([a-z]+)ch
regexp: p([a-z]+)ch
a <fruit>
a PEACH