Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

extract a specific string from input

by lucifer7748 (Initiate)
on Sep 26, 2012 at 10:40 UTC ( #995738=perlquestion: print w/ replies, xml ) Need Help??
lucifer7748 has asked for the wisdom of the Perl Monks concerning the following question:

Hi ; I want to extract the string starts with ATT and ends with TAA from input , as a part of my program . I tried the /ATT.TAA/ meta character . but it didn't work . please help me

Comment on extract a specific string from input
Replies are listed 'Best First'.
Re: extract a specific string from input
by clueless newbie (Hermit) on Sep 26, 2012 at 11:30 UTC

    .* will get you the longest sequence of characters.

    .*? will get you the shortest sequence.

      .*? will get you the shortest sequence.

      Usually that's correct, but not if there is overlap between the stand and the end delimiter. ATTAA is the shortest sequence that begins wtih ATT and ends with TAA, but ATT.*?TAA doesn't match it.

      If overlapping matches need to be allowed, you can use for example

      /((?=ATT).*?TAA)/
Re: extract a specific string from input
by Anonymous Monk on Sep 26, 2012 at 10:43 UTC
    how many in between? . means one, try .*

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://995738]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2015-07-08 06:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (96 votes), past polls