Solved

regexp easy one (I think)

Posted on 2000-03-09
4
169 Views
Last Modified: 2010-03-05
This line sets the variable buffer to everything in between the "</HEAD>" tag and the </BODY> tag in a file.  

$buffer =~ m/<\/HEAD>(.*)<\/BODY>/is;

I have a problem in that some of my documents don't have </BODY> tags and some do... I need the line to do this (here is the english)

$buffer is equal to all text in between the </HEAD> tag and either the </BODY> tag, if there is one OR this string: /commonfooter.cgi

help?
0
Comment
Question by:georgia
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 50 total points
ID: 2603064
The | symbol gives you  alternation (OR) in regular expressions.
$buffer =~ m/<\/HEAD>(.*)(<\/BODY>|\/commonfooter.cgi)/is;
print($1);
0
 
LVL 5

Expert Comment

by:PC_User321
ID: 2603143
teraplane, you should escape the literal '.'
0
 

Author Comment

by:georgia
ID: 2603146
Thanks a bunch!
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 2603171
well spotted PC,
$buffer =~ m/<\/HEAD>(.*)(<\/BODY>|\/commonfooter\.cgi)/is;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now