Why the C:\\\\
(quoted by `) regexp does not match "C:\\"
and "C:\\\\"
do ?
r, err := regexp.Compile(`C:\\\\`) // Not match
r, err := regexp.Compile("C:\\\\") // Matches
if r.MatchString("Working on drive C:\\") == true {
fmt.Printf("Matches.")
} else {
fmt.Printf("No match.")
}
Escape sequences in raw string literal (quoted by quotes) are not interpreted.
`C:\\\\`
is equivalent to:
"C:\\\\\\\\"
See The Go Programming Language Specification - String literals.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With