in reply to Regex: save values


Picking apart your regex by using the following code reveals that the the final block of characters is contained in $4. This is the problem. You were mistakingly assigning $2, witch is matched inside the first group,as this code shows.
$string="ctaacxxxxxxxxxxxxxxxxxxxxxxx"; $_=$string; $_=/(ct(a|g)a(c|t))(.{20,50})$/i; print "\n$1,$2,$3,$4"; ($branch,$pyrich)=($1,$4); print "\n$branch$pyrich";
produces:
ctaac,a,c,xxxxxxxxxxxxxxxxxxxxxxx ctaacxxxxxxxxxxxxxxxxxxxxxxx

Hope that helps.

Replies are listed 'Best First'.
Re^2: Regex: save values
by tphyahoo (Vicar) on Jun 13, 2005 at 08:31 UTC
    This might also be a good place to use the extended (/x) regex syntax, with whitespace and comments, and strategic indenting, to better understand what's going on.
    use strict; use warnings; "ctaacxxxxxxxxxxxxxxxxxxxxxxx" =~ / ( #begin $1 ct (a|g) # $2 a (c|t) # $3 ) #end $1 (.{20,50})$ # $4 /ix; print "\n$1,$2,$3,$4"; my ($branch,$pyrich)=($1,$4); print "\n$branch$pyrich";