When you ask a question, the monks are happy to see your effort in the shape of the code you tried before asking for help. But when you're confused about how to write down the algorithm or the program or about Perl itself, it could help a prose description of what you're trying to do. Sometimes you'll be surprised about how people may offer simpler solutions you haven't thought about it.

Well, after this unsolicited introduction, I am not sure what you're trying to do. Maybe replacing literal escape sequences like '\n' with their meaning "\n", which could be done with code like

my %map = ( '\n' => "\n", '\t' => "\t" ); $_ = "whatever"; s/(\\[ntf\\])/$map{$1}||'?'/g
Or maybe you're trying to do the opposite: turn newlines ("\n"), tabs ("\t") into escapes ('\n', '\t'). Where something like this might work
my %imap = ( "\n" => '\n', "\t" => '\t' ); my $specials = join '|', keys %imap; $_ = "a\nb\tcksl"; s/($specials)/$imap{$1}/gms;

But you may find useful a ready-to-use module like Text::Quote as well.


In reply to Re: Regex to dereference by ferreira
in thread Regex to dereference by Hena

Title:
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, details, 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, summary, 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.