Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Understanding a portion of perlretut

by Corion (Patriarch)
on Dec 09, 2015 at 15:19 UTC ( [id://1149781]=note: print w/replies, xml ) Need Help??


in reply to Re: Understanding a portion of perlretut
in thread Understanding a portion on the Perlretut

I thought the documentation said that:

... which prints
Got a TGA stop codon at position 18 Got a TGA stop codon at position 23

Position 18 is good, but position 23 is bogus. What happened?

The answer is that our regexp works well until we get past the last real match. Then the regexp will fail to match a synchronized TGA and start stepping ahead one character position at a time, not what we want. The solution is to use \G to anchor the match to the codon alignment: ...

If there is no match at all, I would assume that we are always past the last real match.

Replies are listed 'Best First'.
Re^3: Understanding a portion of perlretut
by BlueStarry (Novice) on Dec 09, 2015 at 15:52 UTC
    By the way, i still don't understand where the regexp backtracks when it fails and test again. (\w\w\w)*?TGA

    ATCGTTGAA

    Step 1: match the leftmost part 0 times ok, no TGA after, therefore no match. Step2: We start from?

      Step 2 is to try the leftmost part 1 time (no TGA found).

      Step 3 is to try the leftmost part 2 times (no TGA found).

      Step 4 (and this is where the naive part goes bad) is to advance the leftmost starting point by one, since the match is unanchored.

        can you elaborate more please? I cannot understand you. Because following your steps, the short string wouldn't match. Trying the leftmost part 2 times means ATCGTT = (\w\w\w)*? ok? 2 times. But how it is possible that it matches on CGTTGA, i cannot understand.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1149781]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-04-23 13:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found