Go中的正则表达式字符串[重复]

This question already has an answer here:

I try to use string

"/{foo}/{bar:[a-zA-Z0-9=\-\/]+}.{vzz}"

in Go.

When I use ", I see error:

unknown escape sequence

When I use ', I get:

cannot use '\u0000' (type rune) as type string in array or slice literal
unknown escape sequence

How I can use this regular expression for MUX in my Go application?

</div>

When you mean \ character literally in string literals - it must be escaped additionally

"/{foo}/{bar:[a-zA-Z0-9=\\-\\/]+}.{vzz}"

otherwise you could use backticks instead of double quotes

`/{foo}/{bar:[a-zA-Z0-9=\-\/]+}.{vzz}`

According to Golang Language Specification.

string_lit             = raw_string_lit | interpreted_string_lit .
raw_string_lit         = "`" { unicode_char | newline } "`" .
interpreted_string_lit = `"` { unicode_value | byte_value } `"` .

So if you do not want to escape anything in your string literal, you need a raw one. and

The value of a raw string literal is the string composed of the uninterpreted (implicitly UTF-8-encoded) characters between the quotes

Golang does not use single quote ' as a string literal indicator. And your error with the double quote " is due to the compiler trying to escape \- and \/ as a part of the string before the regex interpreter.