Not sure I really understand what you are looking for. My understanding is that your are looking for substrings like __(...) with various possible types of strings between the parentheses. I would suggest to use a regex to find these general patterns and then call a function to process (with further regexes) what's in between. It could look like this:

sub process { print shift, "\n"; } my $string = "ccc __(dddd)ccc __(eeee)ssss"; $string =~ s/__\(([^)]+)\)/process($_)/egis;

The advantage is to split the complex regex into two pieces, one applied to the larger text and then one for the template bits you have extracted. You could even call it recursively. Whether or not this makes sense or is faster, you would have to try.


In reply to Re: regex for translation by hdb
in thread regex for translation by klayman

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.