in reply to Regular expressions

You're pretty close. I think the problem is that you're being 'greedy' in the regex. I've added a ? after the .* to make it non-greedy. The ?: tells the inner parens to not capture. The outer parens will do this for us.

This example captures everything including the delimiters:

m/(ATG.*?(?:TAG|TAA|TGA))/g

This one will capture only inside the delimiters:

m/ATG(.*?)(?:TAG|TAA|TGA)/g

Replies are listed 'Best First'.
Re^2: Regular expressions
by lairel (Novice) on Oct 27, 2015 at 16:38 UTC

    this may be a stupid question, but what is the function of the :

      As I said, the ?: makes it so the group within the () is not captured. Observe...

      Without ?::

      perl -E '"123" =~ /(2|3)/; say $1' 2

      With ?::

      perl -E '"123" =~ /(?:2|3)/; say $1'

      Note how using the ?: doesn't put anything into the special numbered $1 variable. See perlretut's Non-Capturing Groupings