Replace first occurrence of string using Regexp

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)
}
C:\golang\coding>go run example11.go
Java-Golang-Php-Python-Php-Kotlin

C:\golang\coding>

Thanks for reading. Please leave your valuable feedback and comments.

* Required Fields

No questions yet. Be the first to ask the question!