Von_Halen has asked for the wisdom of the Perl Monks concerning the following question:
Oh wise seekers of the Perl Wisdom, I come seeking help. This is, I am sure, a novice question and most likely a stupid one... But I've tried everything I can think of and can't seem to get this to work. I ran into an issue where words in parentheses are not being removed from a regex as wanted... The goal is to have anything inside of the curly braces (including the curly braces themselves) to disappear from the string. This works for all circumstances except for when there is a set of parentheses in the text.. I tried escaping the parentheses "\( and \)", but it was to no avail.. I understand that the parentheses are grouping tools in regex, but I figured escaping them would fix that problem, and it did not...
Output:my $text = "to { (This Word) }"; my $remove = "{ (This Word) }"; $text =~ s/\R//g; $text =~ s/$remove//; print $remove, $/, $/; print $text;
Looking for someone to shed some light on the situation, as it's holding up my production. Again, I'm sorry for I'm sure this is a simple thing to fix..{ (This Word) } to { (This Word) }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question about parentheses in regex
by toolic (Bishop) on May 27, 2015 at 19:14 UTC | |
by Von_Halen (Novice) on May 27, 2015 at 19:17 UTC | |
by choroba (Cardinal) on May 27, 2015 at 19:23 UTC | |
by ww (Archbishop) on May 27, 2015 at 19:41 UTC | |
by Anonymous Monk on May 28, 2015 at 02:54 UTC | |
|
Re: Question about parentheses in regex
by Sathishkumar (Scribe) on May 28, 2015 at 06:39 UTC |