?
Solved

substitution

Posted on 2000-03-28
6
Medium Priority
?
230 Views
Last Modified: 2010-03-05
I have an HTML file with comments like:

<!-- cgi:SOMETHING -->

I want to parse that file under two conditions. The first condition will replace those comments with data like($buffer contains the entire HTML file):

$buffer =~ s/<!-- cgi:SOMETHING -->/$my_data/g;

The other instance of parsing this file get rid of those comments alltogether. So I want to parse $buffer and anywhere it sees a comment, it replaces it with nothing. However, the SOMETHING in the comment will be different for each comment, so how would I write the substitution command to replace all comments with nothing?

-Mike K.
0
Comment
Question by:lunaboy
[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
6 Comments
 
LVL 2

Expert Comment

by:djsansui
ID: 2665993
I think what you're aiming for is:
$buffer =~ s/<!--(.|\n)*-->//g;
0
 
LVL 1

Author Comment

by:lunaboy
ID: 2666031
no, that deletes all the lines that contain comments... I just need to delete the comments themselves...
0
 
LVL 1

Author Comment

by:lunaboy
ID: 2666034
no, that deletes all the lines that contain comments... I just need to delete the comments themselves...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Accepted Solution

by:
PC_User321 earned 200 total points
ID: 2666067
$buffer =~ s/<!--.*?-->//g;
0
 
LVL 5

Expert Comment

by:pitonyak
ID: 2666079
Will the comments have any particular structure such as potentially including embedded HTML then you have a little problem. My concern is that you will end your replacement before you need to. Also, will there be any escape characters?

0
 
LVL 1

Author Comment

by:lunaboy
ID: 2666103
pitonyak - The comments will only be like:

<!-- cgi: SOMETHING -->

where SOMETHING is any single word. It's used for a template. The script parses the HMTL file, replaces the comments with the appropriate data, and prints it. However, I have another script that I wanted to print the same HTML without the dynamic data. So I wanted that script to replace all those comments with nothing.

PC User321 answered correctly, he will get the points this time.

-Mike K.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

764 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