Any way to escape a Go string in a regular expression?
问题 I'm wanting to match ^(@|\s)*{{string}}:? whereas {{string}} is dynamically defined. It may have periods and dashes and any number of things in it and I really need for it to be escaped. PHP provides a preg_quote method that escapes all special characters safely. I was wondering if Go provides any sort of analog. 回答1: regexp.QuoteMeta does the deed. 来源: https://stackoverflow.com/questions/27415532/any-way-to-escape-a-go-string-in-a-regular-expression