in reply to Split a string to remove quotes and parentheses

You say you are trying to "split" the string, but it looks like you just want to remove unwanted characters. Everyone has pointed out variations on  s/[()"]+//g which certainly works.

Another way is the "tr" operator, which simply does character transliterations. In this case, you can "transliterate" the unwanted characters to nothing -- i.e. delete them:

my $string = '"(test123)"'; $string =~ tr/()"//d;
This is a simpler operation than regex substitution, so if your code needs to do this a lot, you could see a performance difference.

Replies are listed 'Best First'.
Re^2: Split a string to remove quotes and parentheses
by Anonymous Monk on May 31, 2016 at 13:34 UTC
    I have a similar problem to the one presented here. I have a string with dates and alternative representation of those dates in parentheses. E.g., .....5 June 2010 (June 10, 2005).... The tr solution given here is much simpler for my purposes. Thanks! Less is more!