RosettaCodeData/Task/Regular-expressions/Go/regular-expressions.go

17 lines
347 B
Go

package main
import "fmt"
import "regexp"
func main() {
str := "I am the original string"
// Test
matched, _ := regexp.MatchString(".*string$", str)
if matched { fmt.Println("ends with 'string'") }
// Substitute
pattern := regexp.MustCompile("original")
result := pattern.ReplaceAllString(str, "modified")
fmt.Println(result)
}