You can use
grep if you are using the GNU version of
grep, which has the
-P option for perl-compatible regular expressions (PCRE).
Alternatively, you could use
pgrep) by the author of the PCRE library. There's not much reason to use this these days unless you are using an old version of GNU grep, or a non-GNU grep, that doesn't suppoer the
-P option and can't be upgraded or replaced.
e.g. (assuming that the sequences are in a file called
$ grep -oP 'ATG.*?TA[AG]' input.txt
-o option tells GNU grep to output only the matching text, not the entire line, and the
-P tells it to use perl-compatible regular expressions.
Or, if you're using
$ pcregrep -o 'ATG.*?TA[AG]' input.txt
? modifier in the regexp (
.*?) ensures that it captures ALL matching patterns, not just the longest one. In the context of regular expressions, "greedy" means "try to match as MUCH as possible" (the default), and "non-greedy" means "try to match as LITTLE as possible".
There's a good explanation of this at https://www.regular-expressions.info/repeat.html. BTW, the rest of that site is a pretty good place to learn about regular expressions, with lots of tutorials and examples.
Note that most regular expression libraries do not implement non-greedy matches, it is a perl extension that has also been adopted by GNU grep. and programs linked with PCRE, of course.
BTW, This is what the output would look like without the non-greedy modifier:
$ grep -oP 'ATG.*TA[AG]' input.txt