How to replace all html tags of one kind with another [duplicate]












0
















This question already has an answer here:




  • Find and replace HTML tags

    3 answers




I need to replace all HTML tags of one kind in a string with another, e.g., replace all <i> tags with <em> tag.



What's the best way to effectively change:



"<p><i>Random stuff here...</i></p>"


to the following?



"<p><em>Random stuff here...</em></p>"


There are millions of such strings, so a solution taking complexity into account would be nice.










share|improve this question















marked as duplicate by sawa ruby
Users with the  ruby badge can single-handedly close ruby questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 5:27


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • If your html tags are into files, you can posibly use your code editor, Visual Code have a find and replace tool, but if your html tags are saved into a database you will probably need to replace the tags from a script, Gsub is your frind. Check: stackoverflow.com/questions/18587022/…

    – hernanvicente
    Nov 21 '18 at 17:00


















0
















This question already has an answer here:




  • Find and replace HTML tags

    3 answers




I need to replace all HTML tags of one kind in a string with another, e.g., replace all <i> tags with <em> tag.



What's the best way to effectively change:



"<p><i>Random stuff here...</i></p>"


to the following?



"<p><em>Random stuff here...</em></p>"


There are millions of such strings, so a solution taking complexity into account would be nice.










share|improve this question















marked as duplicate by sawa ruby
Users with the  ruby badge can single-handedly close ruby questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 5:27


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • If your html tags are into files, you can posibly use your code editor, Visual Code have a find and replace tool, but if your html tags are saved into a database you will probably need to replace the tags from a script, Gsub is your frind. Check: stackoverflow.com/questions/18587022/…

    – hernanvicente
    Nov 21 '18 at 17:00
















0












0








0









This question already has an answer here:




  • Find and replace HTML tags

    3 answers




I need to replace all HTML tags of one kind in a string with another, e.g., replace all <i> tags with <em> tag.



What's the best way to effectively change:



"<p><i>Random stuff here...</i></p>"


to the following?



"<p><em>Random stuff here...</em></p>"


There are millions of such strings, so a solution taking complexity into account would be nice.










share|improve this question

















This question already has an answer here:




  • Find and replace HTML tags

    3 answers




I need to replace all HTML tags of one kind in a string with another, e.g., replace all <i> tags with <em> tag.



What's the best way to effectively change:



"<p><i>Random stuff here...</i></p>"


to the following?



"<p><em>Random stuff here...</em></p>"


There are millions of such strings, so a solution taking complexity into account would be nice.





This question already has an answer here:




  • Find and replace HTML tags

    3 answers








html ruby string






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 5:31









sawa

131k29205303




131k29205303










asked Nov 21 '18 at 16:44









user3903418user3903418

235




235




marked as duplicate by sawa ruby
Users with the  ruby badge can single-handedly close ruby questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 5:27


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by sawa ruby
Users with the  ruby badge can single-handedly close ruby questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 5:27


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • If your html tags are into files, you can posibly use your code editor, Visual Code have a find and replace tool, but if your html tags are saved into a database you will probably need to replace the tags from a script, Gsub is your frind. Check: stackoverflow.com/questions/18587022/…

    – hernanvicente
    Nov 21 '18 at 17:00





















  • If your html tags are into files, you can posibly use your code editor, Visual Code have a find and replace tool, but if your html tags are saved into a database you will probably need to replace the tags from a script, Gsub is your frind. Check: stackoverflow.com/questions/18587022/…

    – hernanvicente
    Nov 21 '18 at 17:00



















If your html tags are into files, you can posibly use your code editor, Visual Code have a find and replace tool, but if your html tags are saved into a database you will probably need to replace the tags from a script, Gsub is your frind. Check: stackoverflow.com/questions/18587022/…

– hernanvicente
Nov 21 '18 at 17:00







If your html tags are into files, you can posibly use your code editor, Visual Code have a find and replace tool, but if your html tags are saved into a database you will probably need to replace the tags from a script, Gsub is your frind. Check: stackoverflow.com/questions/18587022/…

– hernanvicente
Nov 21 '18 at 17:00














1 Answer
1






active

oldest

votes


















2














You can make use gsub with block



string = "<p><i>Random stuff here...</i></p>"

string.gsub(/(</?)i(>)/) { "#{$1}em#{$2}" }
#=> "<p><em>Random stuff here...</em></p>"


Explanation:



Match an i html opening or closing tag and replace it with em






share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You can make use gsub with block



    string = "<p><i>Random stuff here...</i></p>"

    string.gsub(/(</?)i(>)/) { "#{$1}em#{$2}" }
    #=> "<p><em>Random stuff here...</em></p>"


    Explanation:



    Match an i html opening or closing tag and replace it with em






    share|improve this answer




























      2














      You can make use gsub with block



      string = "<p><i>Random stuff here...</i></p>"

      string.gsub(/(</?)i(>)/) { "#{$1}em#{$2}" }
      #=> "<p><em>Random stuff here...</em></p>"


      Explanation:



      Match an i html opening or closing tag and replace it with em






      share|improve this answer


























        2












        2








        2







        You can make use gsub with block



        string = "<p><i>Random stuff here...</i></p>"

        string.gsub(/(</?)i(>)/) { "#{$1}em#{$2}" }
        #=> "<p><em>Random stuff here...</em></p>"


        Explanation:



        Match an i html opening or closing tag and replace it with em






        share|improve this answer













        You can make use gsub with block



        string = "<p><i>Random stuff here...</i></p>"

        string.gsub(/(</?)i(>)/) { "#{$1}em#{$2}" }
        #=> "<p><em>Random stuff here...</em></p>"


        Explanation:



        Match an i html opening or closing tag and replace it with em







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 17:10









        Deepak MahakaleDeepak Mahakale

        14.5k53954




        14.5k53954

















            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith