This node is inspired by the following (excerpt from the) comment by BrowserUk in Re: Re: Re: looking for a regex

s_\{.*?\}_{$sub[$n++]}_g;

I'm not at all sure about using _ as the delimiter, but everything else I tried was altogether too messy.

Assuming that the traditional '/' is not available, I would have written that as one of the following

# For the sake of the discussion lets ignore the fact the # curlies didnt need to be escaped. s!{.*?}!{$sub[$n++]}!g; s:{.*?}:{$sub[$n++]}:g;

And I certainly wouldn't have done what I know is popular amongst some monks

s#{.*?}#{$sub[$n++]}#g;

Because I find it makes the code hard to understand at a glance, especially in an editor that doesnt know that the # in this context isnt a comment begin marker.

So what are the monks at large opinion on this ever so trivial a subject? Which alternate regex delimiter do you favour? And what are the arguments behind your opinion (if any)?


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

In reply to Whats your favorite nonstandard regex quote char? by demerphq

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.