Link to home
Start Free TrialLog in
Avatar of weversbv
weversbv

asked on

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

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!";
Avatar of ultimatemike
ultimatemike


This'll replace each possible case with a newline.


 use strict;

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

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

 print;
ASKER CERTIFIED SOLUTION
Avatar of ultimatemike
ultimatemike

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!

sorry, did some cross posting :-S.  Mike was too fast ;-)