How to replace all html tags of one kind with another [duplicate]
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.
html ruby string
marked as duplicate by sawa
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.
add a comment |
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.
html ruby string
marked as duplicate by sawa
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
add a comment |
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.
html ruby string
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
html ruby string
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
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
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
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
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
answered Nov 21 '18 at 17:10
Deepak MahakaleDeepak Mahakale
14.5k53954
14.5k53954
add a comment |
add a comment |
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