I am trying to capture the very short string after the 'atg' and before (not including) either 'taa', 'tag', or 'tga'.

This doesn't explain adequately what you're trying to match,

but the program/regex you posted does actually match, so what is the problem that you're trying to solve?

see how it runs with use re 'debug';

#!/usr/bin/perl -- use warnings; use strict; use re 'debug'; my $dna = 'atctcggataatgggataaaaatataggctataaatggcgccccggctaattttt'; if ($dna =~ /atg([acgt]+)(?!(taa|tag|tga))/xms) { print $1; } __END__ $ perl fudge Compiling REx "atg([acgt]+)(?!(taa|tag|tga))" Final program: 1: EXACT <atg> (3) 3: OPEN1 (5) 5: PLUS (17) 6: ANYOF[acgt][] (0) 17: CLOSE1 (19) 19: UNLESSM[0] (36) 21: OPEN2 (23) 23: EXACT <t> (25) 25: TRIE-EXACT[ag] (32) <aa> <ag> <ga> 32: CLOSE2 (34) 34: SUCCEED (0) 35: TAIL (36) 36: END (0) anchored "atg" at 0 (checking anchored) minlen 4 Guessing start of match in sv for REx "atg([acgt]+)(?!(taa|tag|tga))" +against "atctcggataatgggataaaaatataggctataaatggcgc cccggctaattttt" Found anchored substr "atg" at offset 10... Starting position does not contradict /^/m... Guessed: match at offset 10 Matching REx "atg([acgt]+)(?!(taa|tag|tga))" against "atgggataaaaatata +ggctataaatggcgccccggctaattttt" 10 <ggata> <atgggataaa> | 1:EXACT <atg>(3) 13 <taatg> <ggataaaaat> | 3:OPEN1(5) 13 <taatg> <ggataaaaat> | 5:PLUS(17) ANYOF[acgt][] can match 42 times out + of 2147483647... 55 <cggctaattttt> <> | 17: CLOSE1(19) 55 <cggctaattttt> <> | 19: UNLESSM[0](36) 55 <cggctaattttt> <> | 21: OPEN2(23) 55 <cggctaattttt> <> | 23: EXACT <t>(25) failed... 55 <cggctaattttt> <> | 36: END(0) Match successful! ggataaaaatataggctataaatggcgccccggctaatttttFreeing REx: "atg([acgt]+)(? +!(taa|tag|tga))"

In reply to Re: Simple regex question. Grouping with a negative lookahead assertion. by Anonymous Monk
in thread Simple regex question. Grouping with a negative lookahead assertion. 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.