Solved

substitution

Posted on 2000-03-28
6
215 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl efficient DB Call 8 81
problem with using the glob function 1 63
Any syntax error for this clone.plscript 6 132
.properties file to call function/method 9 59
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

947 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now