簡體   English   中英

`和'引用的正則表達式有什么區別?

[英]What is the difference between a regular expression quoted by ` and "?

為什么C:\\\\\\\\ (由`引用) "C:\\\\""C:\\\\\\\\"不匹配?

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.")
}

原始字符串文字中的轉義序列(引用引號)不會被解釋。

`C:\\\\`

相當於:

"C:\\\\\\\\"

請參閱Go編程語言規范 - 字符串文字

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM