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\nrepl acement!";
Replace:
$test = "this is<br>working<br />example<br/>replacement!
to
$test = "this is\nworking\nexample\nrepl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!
#!/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 ;-)
This'll replace each possible case with a newline.
use strict;
$_ = "a<br>b<br/>c<br />";
s/<br>|<br\/>|<br \/>/\n/g;
print;