• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

regexp easy one (I think)

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
georgia
Asked:
georgia
  • 2
1 Solution
 
Kim RyanIT ConsultantCommented:
The | symbol gives you  alternation (OR) in regular expressions.
$buffer =~ m/<\/HEAD>(.*)(<\/BODY>|\/commonfooter.cgi)/is;
print($1);
0
 
PC_User321Commented:
teraplane, you should escape the literal '.'
0
 
georgiaAuthor Commented:
Thanks a bunch!
0
 
Kim RyanIT ConsultantCommented:
well spotted PC,
$buffer =~ m/<\/HEAD>(.*)(<\/BODY>|\/commonfooter\.cgi)/is;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now