简体   繁体   English

正则表达式从字符串中删除括号

[英]RegEx remove parentheses from string

If I have:如果我有:

string = (1000.00)

How can I use regex to remove the parentheses and get the output as 1000.00 ?如何使用正则表达式删除括号并获得输出1000.00

Thanks谢谢

Try this regular expression:试试这个正则表达式:

s/([()])//g

Brief explanation: [] is used to create a character set for any regular expression.简要说明: []用于为任何正则表达式创建字符集 My character set for this particular case is composed of ( and ) .我在这个特殊情况下的字符集()组成。 So overall, substitute ( and ) with an empty string.所以总的来说,用空字符串替换()

Replace the pattern:更换图案:

\((.+?)\)

With the replacement pattern:使用替换模式:

\1

Note the escaping of the parentheses () for their literal meaning as parenthesis characters.请注意括号()的转义,因为它们的字面意思是括号字符。

Perl syntax: /\\(([0-9\\.]+)\\)/ (untested) Perl 语法:/ /\\(([0-9\\.]+)\\)/ (([ /\\(([0-9\\.]+)\\)/ ) /\\(([0-9\\.]+)\\)/ (未经测试)

UPDATE : (more strict)更新:(更严格)

Perl syntax: /\\((-?[0-9]+\\.[0-9]*)\\)/ Perl 语法:/ /\\((-?[0-9]+\\.[0-9]*)\\)/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM