in reply to Question about parentheses in regex

quotemeta
use warnings; use strict; my $text = "to { (This Word) }"; my $remove = quotemeta "{ (This Word) }"; $text =~ s/\R//g; $text =~ s/$remove//; print $remove, $/, $/; print $text; print "\n"; __END__ \{\ \(This\ Word\)\ \} to

Replies are listed 'Best First'.
Re^2: Question about parentheses in regex
by Von_Halen (Novice) on May 27, 2015 at 19:17 UTC
    Oh my god, I love you. Thank you very much. What does the quotemeta do in this case?
      my $remove = quotemeta "{ (This Word) }"; print $remove; # See what happened.

      You can also shorten it to

      my $text = 'to { (This Word) }'; my $remove = '{ (This Word) }'; $text =~ s/\R//g; $text =~ s/\Q$remove//; # <-- the \Q means quotemeta
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      "What does the quotemeta do...?"

      That's thoroughly explained in the docs. Ask your Teddy Bear ... uh, no, I mean, ask your machine's command line interface (using perldoc perlop [look for "Quote and Quote-like Operators"] or ask your browser using a search engine for http://perldoc.perl.org/functions/quotemeta.html which will tell you all about it.

      We value sell-help self-help very highly here in the Monastery. You'll also find interesting (and helpful) information about site's expectations of those asking questions at PerlMonks FAQ section.

      Edited: Typo fixed. TY soonix for catching what I should have.