Try m//ms instead if //gs

Also, use re 'debug'; to see how the regex engine matches your string ... you can also use rxrx - command-line REPL and wrapper for Regexp::Debugger

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; my $line7 = q{ CDS join(2432..2501,5144..5154,57 /translation="MLSFVDTRTLLL" exon 2432..2501 }; my $amino_acid_seq; { use re 'debug'; ($amino_acid_seq ) = $line7 =~ m/^\s+\/translation\=\"(.*?)\"/s; } dd( $amino_acid_seq ); { use re 'debug'; ($amino_acid_seq ) = $line7 =~ m/^\s+\/translation\=\"(.*?)\"/ms; } dd( $amino_acid_seq ); __END__ Compiling REx "^\s+/translation\=\%"(.*?)\%"" Final program: 1: SBOL (2) 2: PLUS (4) 3: SPACE (0) 4: EXACT </translation="> (9) 9: OPEN1 (11) 11: MINMOD (12) 12: STAR (14) 13: SANY (0) 14: CLOSE1 (16) 16: EXACT <"> (18) 18: END (0) floating "/translation=%"" at 1..2147483647 (checking floating) anchor +ed(SBOL) minlen 16 Compiling REx "^\s+/translation\=\%"(.*?)\%"" Final program: 1: MBOL (2) 2: PLUS (4) 3: SPACE (0) 4: EXACT </translation="> (9) 9: OPEN1 (11) 11: MINMOD (12) 12: STAR (14) 13: SANY (0) 14: CLOSE1 (16) 16: EXACT <"> (18) 18: END (0) floating "/translation=%"" at 1..2147483647 (checking floating) anchor +ed(MBOL) minlen 16 Guessing start of match in sv for REx "^\s+/translation\=\%"(.*?)\%"" +against "%nCDS join(2432..2501,5144..5 154,57%n "... Found floating substr "/translation=%"" at offset 68... Guessed: match at offset 0 Matching REx "^\s+/translation\=\%"(.*?)\%"" against "%nCDS + join(2432..2501,5144..5154,57%n "... 0 <> <%nCDS > | 1:SBOL(2) 0 <> <%nCDS > | 2:PLUS(4) SPACE can match 1 times out of 21474 +83647... failed... Match failed undef Guessing start of match in sv for REx "^\s+/translation\=\%"(.*?)\%"" +against "%nCDS join(2432..2501,5144..5 154,57%n "... Found floating substr "/translation=%"" at offset 68... Position at offset 0 does not contradict /^/m... Guessed: match at offset 0 Matching REx "^\s+/translation\=\%"(.*?)\%"" against "%nCDS + join(2432..2501,5144..5154,57%n "... 0 <> <%nCDS > | 1:MBOL(2) 0 <> <%nCDS > | 2:PLUS(4) SPACE can match 1 times out of 21474 +83647... failed... Guessing start of match in sv for REx "^\s+/translation\=\%"(.*?)\%"" +against "CDS join(2432..2501,5144..515 4,57%n "... Found floating substr "/translation=%"" at offset 67... Position at offset 0 does not contradict /^/m... Guessed: match at offset 0 1 <%n> <CDS > | 1:MBOL(2) 1 <%n> <CDS > | 2:PLUS(4) SPACE can match 0 times out of 21474 +83647... failed... Guessing start of match in sv for REx "^\s+/translation\=\%"(.*?)\%"" +against "DS join(2432..2501,5144..5154 ,57%n "... Found floating substr "/translation=%"" at offset 66... Found /^/m at offset 45... Guessed: match at offset 45 47 <4,57%n> < > | 1:MBOL(2) 47 <4,57%n> < > | 2:PLUS(4) SPACE can match 21 times out of 2147 +483647... 68 < > </translati> | 4: EXACT </translation=">(9) 82 <ion="> <MLSFVDTRTL> | 9: OPEN1(11) 82 <ion="> <MLSFVDTRTL> | 11: MINMOD(12) 82 <ion="> <MLSFVDTRTL> | 12: STAR(14) SANY can match 12 times out of 12. +.. 94 <RTLLL> <"%n > | 14: CLOSE1(16) 94 <RTLLL> <"%n > | 16: EXACT <">(18) 95 <TLLL"> <%n > | 18: END(0) Match successful! "MLSFVDTRTLLL" Freeing REx: "^\s+/translation\=\%"(.*?)\%"" Freeing REx: "^\s+/translation\=\%"(.*?)\%""

Also interesting (but tad more pita to install) is wxPPIxregexplain.pl


In reply to Re^4: Help to build a REGEXP (m//ms) by Anonymous Monk
in thread Help to build a REGEXP by Anonymous Monk

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.