Introduction
This challenge demonstrates how to use regular expressions in Golang.
This tutorial is from open-source community. Access the source code
This challenge demonstrates how to use regular expressions in Golang.
The challenge requires you to complete the code to perform various regular expression-related tasks in Golang.
regexp
package to perform regular expression-related tasks.MatchString
to test whether a pattern matches a string.Compile
to optimize a Regexp
struct.MatchString
to test a match like Compile
.FindString
to find the match for the regexp.FindStringIndex
to find the first match and return the start and end indexes for the match instead of the matching text.FindStringSubmatch
to return information for both p([a-z]+)ch
and ([a-z]+)
.FindStringSubmatchIndex
to return information about the indexes of matches and submatches.FindAllString
to find all matches for a regexp.FindAllStringSubmatchIndex
to apply to all matches in the input, not just the first.Match
to test a match with []byte
arguments and drop String
from the function name.MustCompile
to create global variables with regular expressions.ReplaceAllString
to replace subsets of strings with other values.ReplaceAllFunc
to transform matched text with a given function.$ go run regular-expressions.go
true
true
peach
idx: [0 5]
[peach ea]
[0 5 1 3]
[peach punch pinch]
all: [[0 5 1 3] [6 11 7 9] [12 17 13 15]]
[peach punch]
true
regexp: p([a-z]+)ch
a <fruit>
a PEACH
## For a complete reference on Go regular expressions check
## the [`regexp`](https://pkg.go.dev/regexp) package docs.
This challenge demonstrates how to use regular expressions in Golang to perform various tasks such as testing whether a pattern matches a string, finding the match for the regexp, and replacing subsets of strings with other values.