Solved

regexp easy one (I think)

Posted on 2000-03-09
4
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans

631 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