Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching Statments

Status
Not open for further replies.

biobrain

MIS
Joined
Jun 21, 2007
Messages
90
Location
GB
Dear All,

I want to retrieve some information from some files. Can you please help me in writing the matching statements.

HEADER PROTEIN KINASE/COMPLEX 07-MAY-04 1VYW

From this line starting must start with HEADER I want to match last word composed of any four characters as "1VYW" . This word can be like 6cO8 , 7mnT , 8Ctv etc any thing.
 
Code:
/^HEADER[\s\S]+(....)$/;
print $1;

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Dear I can understand this like

^ mean start with

I want to understand this area [\s\S]+(....)$/;/ if you can help me

What $ sign is and what others are.


With Best Of Regards
 
Thanks ,

In case my target statement is like

HEADER PROTEIN KINASE/COMPLEX 07-MAY-04 1VYW abcdefghijkl

then how i can pick these four bytes corresponding to IVYW i.e if this is not the lats one
 
give it a try, if your get stuck, post your code.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Dear Kevin,

Thanks for your reply,

I have tried

Code:
if ($_=~/^HEADER[\s\S]+(....)..............$/)
   {

This has worked for me.
 
biobrain, your last code will only work if the last field is presente and if its length is always the same.
If you can have both situations, where what you seek is the last OR (the last but one AND the last is NOT 4 characters long), why not doing it this way?
Code:
if(/^HEADER\s/){
  my@fields=split;
  $myfield=pop@fields unless length($myfield=pop@fields)==4;
}

prex1
: Online tools for structural design
: Magnetic brakes for fun rides
: Air bearing pads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top