Solved

replace <br>, <br/> and <br /> by \n

Posted on 2003-10-27
4
1,235 Views
Last Modified: 2006-11-17
How to replace - in one line - every <br>, <br/> and <br /> in line by \n.

Replace:

$test = "this is<br>working<br />example<br/>replacement!";

to

$test = "this is\nworking\nexample\nreplacement!";
0
Comment
Question by:weversbv
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:ultimatemike
ID: 9627770

This'll replace each possible case with a newline.


 use strict;

 $_ = "a<br>b<br/>c<br />";

 s/<br>|<br\/>|<br \/>/\n/g;

 print;
0
 
LVL 2

Accepted Solution

by:
ultimatemike earned 125 total points
ID: 9627814
Actually, that regular expression could be changed to:

It says "a <br" followed by 0 or more spaces, then an optional slash, then a >"

s/<br\s*\/?>/\n/g;
0
 
LVL 3

Expert Comment

by:BioI
ID: 9627845
This should work.  Don 't forget to add the "g" in the substitution for multiple substitution and "i" to make it case insensitive [i assume sometimes you will find <BR> instead of <br>?]..

#!/usr/bin/perl -w
use strict;

my $test = "this is<br>working<br />example<br/>replacement!";
$test =~ s/<br>|<br\/>|<br \/>/\n/ig;
print "test --> ", $test, "\n";

# output
test --> this is
working
example
replacement!

0
 
LVL 3

Expert Comment

by:BioI
ID: 9627858
sorry, did some cross posting :-S.  Mike was too fast ;-)
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
cpan issue 1 61
.properties file to call function/method 9 59
Edit Odbc.ini using perl module 2 78
Perl modules on linux ec2 3 96
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 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

15 Experts available now in Live!

Get 1:1 Help Now