In the general case your problem is ugly to solve with regexes because, from a computer science point of view, you don't need regular expressions but a (deterministic) context-free language.

If the number of possible outcomes is small, you can just construct an alternation manually:

/ACATGT|GCATGC/
If you have larger sets of alternations, your best bet is to assemble the alternatives with a program (perl 5.10 has very good optimizations for larger sets of constant alternatives), or to use assertions like this:
our %map = ( A => 'T', C => 'C' ); /([AC])CATC(??{$map{$1})/

(Untested). But if you do the latter, please read the warnings in perlre first, (??{...}) is an experimental feature.

This one captures the result from the [AC] in the variable $1 and then matches against a transformed version of that.


In reply to Re: Question on conditional regular expressions/backreferences by moritz
in thread Question on conditional regular expressions/backreferences by sterben

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.