aurekha has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.
  • Comment on How to escape metacharacters without backslash it in regex?

Replies are listed 'Best First'.
Re: How to escape metacharacters without backslash it in regex?
by moritz (Cardinal) on Dec 17, 2007 at 13:49 UTC
    You can escape meta chars with \Q...\E, and you can do something like
    my $good_re = quotemeta $evil_re; m/$good_re/;

    But both methods use backslashes under the hood as well.

    Perl 6 regexes will have '...' and "..." quoting (and implicit grouping), there you don't need backslashes at all.

Re: How to escape metacharacters without backslash it in regex?
by Joost (Canon) on Dec 17, 2007 at 13:50 UTC
Re: How to escape metacharacters without backslash it in regex?
by swampyankee (Parson) on Dec 17, 2007 at 13:54 UTC

    Why? Why? Why?

    First, a little bit of explanation as to why you need to do this (and "because I want to" is not a good reason). Second, have you read the Perl Regular Expressions and Perl Regular Expressions Tutorial? If not, please do so.

    I suspect that what you need to do is either use \Q and \E or quotemeta. If those don't do the trick, post an explanation of why they don't fit your requirements, and the code and data that are giving you trouble.


    emc

    Information about American English usage here and here.

    Any Northeastern US area jobs? I'm currently unemployed.

Re: How to escape metacharacters without backslash it in regex?
by toolic (Bishop) on Dec 17, 2007 at 13:49 UTC
    Could you be more specific? What characters are you trying to include in your regex? What have you tried already (show us your code) and why does it not work for you (show us sample input, expected output, and actual output).

    Have you looked at perlretut?

Re: How to escape metacharacters without backslash it in regex?
by ikegami (Patriarch) on Dec 17, 2007 at 19:36 UTC