Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: look for substrings and getting their location

by wolffm (Novice)
on May 09, 2004 at 15:38 UTC ( [id://351856]=note: print w/replies, xml ) Need Help??


in reply to Re: look for substrings and getting their location
in thread look for substrings and getting their location

all of them + location of the beginng of each one

Replies are listed 'Best First'.
Re: Re: Re: look for substrings and getting their location
by davido (Cardinal) on May 09, 2004 at 16:35 UTC
    I think you missed the point to the followup question. Not a Number was asking if you want overlapping matches to count too. In other words, we already know you want to count all of the "GUAUG"'s in a string like: "GUAUGGUAUG".

    But do you also want to find two matches in a string with overlapping keywords? Like this: "GUAUGUAUG"... If that's the case, your RE will need zero-width lookahead. Something like this:

    /G(?=UAUG)/g

    That way the "pointer" is advanced one character at a time rather than one keyword at a time, thus allowing for overlapping matches.

    You can find the position (in list context) with pos. In scalar context, the special variables @+ and @- will be helpful. See perlvar for a description of them.

    On the other hand, if you want to find only one match in cases where the sequence appears to overlap, you'll have to define whether you want the left-side of the overlap to match, or the right side.


    Dave

Log In?
Username:
Password:

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

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

    No recent polls found