Replace first occurrence of string using Regexp
Example
package main
import (
"fmt"
"regexp"
)
func main() {
strEx := "Php-Golang-Php-Python-Php-Kotlin"
reStr := regexp.MustCompile("^(.*?)Php(.*)$")
repStr := "${1}Java$2"
output := reStr.ReplaceAllString(strEx, repStr)
fmt.Println(output)
}
Output
Java-Golang-Php-Python-Php-Kotlin
Most Helpful This Week
Regular expression to extract filename from given path in Golang
Regular expression to validate the date format in "dd/mm/yyyy"
How to extract text from between html tag using Regular Expressions in Golang?
Regular expression to extract domain from URL
Regular expression to extract all Non-Alphanumeric Characters from a String
Regular expression to validate phone number