2 回答

TA貢獻1752條經驗 獲得超4個贊
這是執行所需操作的例行程序:
package main
import ("fmt"; "regexp"; "os"; "strings";);
func main () {
reg, error := regexp.Compile ("B");
if error != nil {
fmt.Printf ("Compile failed: %s", error.String ());
os.Exit (1);
}
output := string (reg.ReplaceAll (strings.Bytes ("ABBA"),
strings.Bytes ("A")));
fmt.Println (output);
}

TA貢獻1799條經驗 獲得超6個贊
這是一個小例子。您還可以在Regexp測試課中找到很好的例子
package main
import (
"fmt"
"regexp"
"strings"
)
func main() {
re, _ := regexp.Compile("e")
input := "hello"
replacement := "a"
actual := string(re.ReplaceAll(strings.Bytes(input), strings.Bytes(replacement)))
fmt.Printf("new pattern %s", actual)
}
- 2 回答
- 0 關注
- 385 瀏覽
添加回答
舉報