How to replace first occurrence of substring in a string using RegEx with Go

1 Answer

0 votes
package main

import (
	"fmt"
	"regexp"
)

func main() {
	s := "go php PHP GO Python go GO" 
	
	regexp__ := regexp.MustCompile("^(.*?)GO(.*)$")
	replace := "${1}c++$2"
	s = regexp__.ReplaceAllString(s, replace)
	
	fmt.Println(s)
} 
    
  
     
/*
run:
      
go php PHP c++ Python go GO
  
*/

 



answered Aug 18, 2020 by avibootz
edited Aug 18, 2020 by avibootz
...