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
How to Draw a rectangle in Golang?
Different ways for Integer to String Conversions
Golang download image from given URL
How do you write multi-line strings in Go?
Select single argument from all arguments of variadic function
Regular expression to validate email address
How to extract text from between html tag using Regular Expressions in Golang?
Converting Int data type to Float in Go
How pointer & and * and ** works in Golang?
How to get the current date and time with timestamp in local and other timezones ?