Created
July 21, 2023 08:50
-
-
Save mitsugu/1b87e17c86c888c8e892f6f4317999f6 to your computer and use it in GitHub Desktop.
正規表現のテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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