Any way to escape a Go string in a regular express

2019-02-05 23:14发布

问题:

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.