How to combine regexps?

Carl Banks pavlovevidence at
Wed Aug 5 22:35:23 CEST 2009

On Aug 5, 1:09 pm, kj <no.em... at> wrote:
> One of the nice things one can do with Perl's regexp's is illustrated
> in the following example:
> my $gly = qr/gg[ucag]/i
> my $ala = qr/gc[ucag]/i;
> my $val = qr/gu[ucag]/i;
> my $leu = qr/uu[ag]|cu[ucag]/i;
> my $ile = qr/au[uca]/i;
> my $aliphatic = qr/$gly|$ala|$val|$leu|$ile/;
> In other words, one can build regular expressions by re-combining
> other regular expressions.
> Is there a way to do this with Python's regexps?

Your example is just string manipulation.

You're not combining regexps here, you are combining strings which you
(evidently) will soon use to create a regexp.

Yes, you can do that in Python as well, in exactly the same way, using
Python's string manipulation capabilities.

Carl Banks

More information about the Python-list mailing list