Solved

substitution

Posted on 2000-03-28
6
216 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
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 5

Accepted Solution

by:
PC_User321 earned 50 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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 …
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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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