[英]Ruby: Escape parenthesis in a string
I am doing a database query and want to escape parenthesis in the string, only if its returned in my query results, for example: 我正在执行数据库查询,并且仅在查询结果中返回了字符串时才想对字符串进行转义,例如:
/This is a test string (2013)/ /这是测试字符串(2013)/
How do I do this? 我该怎么做呢?
To create a Regexp with all special characters escaped, use 要创建一个转义了所有特殊字符的正则表达式,请使用
Regexp.new( Regexp.escape(str) )
I hope this is what you are trying to achieve. 我希望这是您要实现的目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.