Skip to content

Instantly share code, notes, and snippets.

@mitsugu
Created July 21, 2023 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitsugu/1b87e17c86c888c8e892f6f4317999f6 to your computer and use it in GitHub Desktop.
Save mitsugu/1b87e17c86c888c8e892f6f4317999f6 to your computer and use it in GitHub Desktop.
正規表現のテスト
package main
import (
"os"
"fmt"
"regexp"
)
func main() {
txt := os.Args[1]
fmt.Printf("org : %v\n",txt)
// regexp.MustCompile と re.ReplaceAllString を 2 回実行しているのを 1 回で済ませたい
re := regexp.MustCompile(`[^\\]\\n`)
txt = re.ReplaceAllString(txt, "\n")
fmt.Printf("%#v\n",txt)
re = regexp.MustCompile(`\\\\n`)
txt = re.ReplaceAllString(txt, "\\n")
fmt.Println(txt)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment