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 for matching HH:MM time format in Golang
Regular expression to validate the date format in "dd/mm/yyyy"
Regular Expression to get a string between parentheses in Golang
Regular expression to extract text between square brackets
How to extract text from between html tag using Regular Expressions in Golang?
Regular expression to validate phone number