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
Get Year, Month, Day, Hour, Min and Second from a specified date
How to get the current date and time with timestamp in local and other timezones ?
Regular expression to validate common Credit Card Numbers
How to convert Go struct to JSON?
How to get Dimensions of an image type jpg jpeg png or gif ?
What is Rune? How to get ASCII value of any character in Go?