MohammedAli_
MohammedAli_

Reputation: 175

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?

Thanks

Upvotes: 10

Views: 50394

Answers (3)

Aziz Shaikh
Aziz Shaikh

Reputation: 16544

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.

Upvotes: 16

Lorenzo Marcon
Lorenzo Marcon

Reputation: 8179

Perl syntax: /\(([0-9\.]+)\)/ (untested)

UPDATE: (more strict)

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

Upvotes: 0

Li-aung Yip
Li-aung Yip

Reputation: 12486

Replace the pattern:

\((.+?)\)

With the replacement pattern:

\1

Note the escaping of the parentheses () for their literal meaning as parenthesis characters.

Upvotes: 9

Related Questions