regexp easy one (I think)

Posted on 2000-03-09
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

Question by:georgia
  • 2
LVL 19

Accepted Solution

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

Expert Comment

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

Author Comment

ID: 2603146
Thanks a bunch!
LVL 19

Expert Comment

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

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTP Error 502.2 - Bad Gateway 3 214
perl search and replace 6 168
Perl script not writing to .csv file 6 109
Move Function in Perl Script 2 68
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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