Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Fellow Monks,
it has already been hard enough to find a good title for this question and even harder for me to find the solution to this problem (which -I am sure- must be very plain and simple, because I am looking for it so long(*))

I am building a regexp dynamically, say

$re = qr(/($<!$a)$b/);
(using a look behind just to make it a little more spicy) where $a and $b will always contain exactly one char, but that char might be special in regexps. For example $a can be "?" or "-" depending on the current situation.

The question is: is there any way (a module at CPAN which I have overlooked or an operator I didn't fully understand or ...) to dynamically escape those w/o me going through a list of special chars and checking them?

(*) A simple rule of programming: the longer you search (for an error, for a solution, for the correct way, ...) the plainer is the answer (read as: the more stupid was the error, the simpler is the solution, the cleaner is the correct way ...) ;-)

Regards... Stefan
you begin bashing the string with a +42 regexp of confusion

In reply to Maybe Escape in Dynamic RegExps by stefan k

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (12)
    As of 2018-06-25 18:48 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (128 votes). Check out past polls.