有什么办法可以在正则表达式中转义Go字符串? [英] Any way to escape a Go string in a regular expression?
本文介绍了有什么办法可以在正则表达式中转义Go字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要匹配 ^(@ | \s)* {{string}}:?
,而{{string}}是动态定义的。
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提供了 preg_quote
PHP provides a preg_quote
method that escapes all special characters safely. I was wondering if Go provides any sort of analog.
推荐答案
regexp.QuoteMeta
做事。
这篇关于有什么办法可以在正则表达式中转义Go字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文