Solved

How to remove a part of a text.

Posted on 2002-04-18
10
134 Views
Last Modified: 2010-03-05
How to remove a part of a text.

I have the folling text:

-----------------------------------
</TR>
<TR>
<TD ALIGN="CENTER" COLSPAN="3">
<br><br>
<!-- ads begin -->
<center>
bla bla bla bla
<!-- ads end -->
</td>
</tr>
</table>
</body>
</html>

--------------------------------------

This is stored in $list.

I want to remove to text from <!-- ads begin -->
till <!-- ads end -->
Incl. <!-- ads begin --> and <!-- ads end -->.

How do do that?
0
Comment
Question by:mmcw
10 Comments
 
LVL 6

Expert Comment

by:andreif
Comment Utility
$list =~ s/<\!\-\- ads begin \-\->.*?<\!\-\- ads end \-\->//gi;
0
 
LVL 6

Expert Comment

by:andreif
Comment Utility
sorry, this one:
$list =~ s/<\!\-\- ads begin \-\->.*?<\!\-\- ads end \-\->//gis;
0
 

Author Comment

by:mmcw
Comment Utility
It will not work?
0
 
LVL 6

Expert Comment

by:andreif
Comment Utility
The second regext works perfectly

$list =~ s/<\!\-\- ads begin \-\->.*?<\!\-\- ads end \-\->//gis;

the difference is "s" modifier - it make . to match new line symbols.
0
 
LVL 6

Expert Comment

by:andreif
Comment Utility
Hi mmcw, does my example work? Have you any problem with this?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 6

Accepted Solution

by:
andreif earned 100 total points
Comment Utility
Please, let me know if this doesn't not work

$list =~ s/<\!\-\- ads begin \-\->.*?<\!\-\- ads end \-\->//gis;
0
 
LVL 6

Expert Comment

by:andreif
Comment Utility
???
0
 

Expert Comment

by:dimk
Comment Utility
$list =~ s/<\!\-\- ads begin \-\->.*\<\!\-\- ads end \-\->//g;
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Most of those \'s are unnecessary
0
 

Author Comment

by:mmcw
Comment Utility
OZO: What would be your answer?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

11 Experts available now in Live!

Get 1:1 Help Now