Reputation: 175
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
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
Reputation: 8179
Perl syntax: /\(([0-9\.]+)\)/
(untested)
UPDATE: (more strict)
Perl syntax: /\((-?[0-9]+\.[0-9]*)\)/
Upvotes: 0
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