从字符串中剥离外括号
我在编写从字符串中去除外括号的正则表达式时遇到一些麻烦(我想确保保留单/双引号内的任何括号):
((0)) becomes 0
(0) becomes 0
('(0845) 187 1262') becomes '(0845) 187 1262'
我有两个正则表达式来匹配左右手外括号:
^[\(]* -- matches out the left outer brackets
[\)]*$ -- matches out the right outer brackets
是吗?可以将两者组合成一个正则表达式吗?
I am having some trouble writing a regex expression that will strip outer brackets from a string (I want to ensure any brackets within single/double quotes are preserved):
((0)) becomes 0
(0) becomes 0
('(0845) 187 1262') becomes '(0845) 187 1262'
I have got two regexes to match the left and right hand outer brackets:
^[\(]* -- matches out the left outer brackets
[\)]*$ -- matches out the right outer brackets
Is it possible to combine both into a single regex?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这一点也不困难,并且您的正则表达式也可以简化,因为您不需要字符类:
Yes, it's not at all difficult, and your regex can be simplified as well, as you don't need character classes: