Search code examples
regexgomux

Regex string in Go


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?


Solution

  • 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}`