I want to replace HTML tags but keep the text in betweenhow to remove html comment tags using sed?How can I...
Languages that we cannot (dis)prove to be Context-Free
How can bays and straits be determined in a procedurally generated map?
Is this a crack on the carbon frame?
How does strength of boric acid solution increase in presence of salicylic acid?
A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?
How can I make my BBEG immortal short of making them a Lich or Vampire?
Why was the small council so happy for Tyrion to become the Master of Coin?
Writing rule stating superpower from different root cause is bad writing
Test if tikzmark exists on same page
In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?
Python: next in for loop
Problem of parity - Can we draw a closed path made up of 20 line segments...
Has the BBC provided arguments for saying Brexit being cancelled is unlikely?
Dragon forelimb placement
If I cast Expeditious Retreat, can I Dash as a bonus action on the same turn?
Are the number of citations and number of published articles the most important criteria for a tenure promotion?
Is it legal for company to use my work email to pretend I still work there?
What does it mean to describe someone as a butt steak?
"You are your self first supporter", a more proper way to say it
How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?
Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?
What is the offset in a seaplane's hull?
How old can references or sources in a thesis be?
How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?
I want to replace HTML tags but keep the text in between
how to remove html comment tags using sed?How can I find and replace multiple blocks of text in multiple documents all at once?Vim regex for wrapping visually selected digits with HTML tagsFind and Replace text between ^ and ~ in Notepad++How to find and replace in the between tags in notepad++Replace but leave between characters unchangedAppend text to lines between two patterns every time they appear in a fileNotepad++ Regex find line pattern but only replace one lineRemove/Change specific Html tags NotePad++Delete all html Tags out of an excel sheet while preserving text inbetween
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I want to replace the HTML tags but keep the text in between.
Find: <span class="Heading3-strong">.*?</span>
Replace: <strong>.*?</strong>
It seems as if something is wrong in the middle...
regex
add a comment |
I want to replace the HTML tags but keep the text in between.
Find: <span class="Heading3-strong">.*?</span>
Replace: <strong>.*?</strong>
It seems as if something is wrong in the middle...
regex
3
Parsing HTML with regex is a hard job. See also stackoverflow.com/q/3577641/372239 and stackoverflow.com/a/1732454/372239
– Toto
yesterday
(Since my post was deleted, let's try as a comment.) Using regex to process any kind of nested markup is a very bad idea. If you're not careful, Tony the Pony will come for you. See also the legendary post over on Stack Overflow.
– Eiríkr Útlendi
1 hour ago
add a comment |
I want to replace the HTML tags but keep the text in between.
Find: <span class="Heading3-strong">.*?</span>
Replace: <strong>.*?</strong>
It seems as if something is wrong in the middle...
regex
I want to replace the HTML tags but keep the text in between.
Find: <span class="Heading3-strong">.*?</span>
Replace: <strong>.*?</strong>
It seems as if something is wrong in the middle...
regex
regex
edited yesterday
Glorfindel
1,51141220
1,51141220
asked yesterday
ymcolahymcolah
61
61
3
Parsing HTML with regex is a hard job. See also stackoverflow.com/q/3577641/372239 and stackoverflow.com/a/1732454/372239
– Toto
yesterday
(Since my post was deleted, let's try as a comment.) Using regex to process any kind of nested markup is a very bad idea. If you're not careful, Tony the Pony will come for you. See also the legendary post over on Stack Overflow.
– Eiríkr Útlendi
1 hour ago
add a comment |
3
Parsing HTML with regex is a hard job. See also stackoverflow.com/q/3577641/372239 and stackoverflow.com/a/1732454/372239
– Toto
yesterday
(Since my post was deleted, let's try as a comment.) Using regex to process any kind of nested markup is a very bad idea. If you're not careful, Tony the Pony will come for you. See also the legendary post over on Stack Overflow.
– Eiríkr Útlendi
1 hour ago
3
3
Parsing HTML with regex is a hard job. See also stackoverflow.com/q/3577641/372239 and stackoverflow.com/a/1732454/372239
– Toto
yesterday
Parsing HTML with regex is a hard job. See also stackoverflow.com/q/3577641/372239 and stackoverflow.com/a/1732454/372239
– Toto
yesterday
(Since my post was deleted, let's try as a comment.) Using regex to process any kind of nested markup is a very bad idea. If you're not careful, Tony the Pony will come for you. See also the legendary post over on Stack Overflow.
– Eiríkr Útlendi
1 hour ago
(Since my post was deleted, let's try as a comment.) Using regex to process any kind of nested markup is a very bad idea. If you're not careful, Tony the Pony will come for you. See also the legendary post over on Stack Overflow.
– Eiríkr Útlendi
1 hour ago
add a comment |
2 Answers
2
active
oldest
votes
It's not clear which program you are using the regex in, but what you're looking for are capturing groups and backreferences.
For example, in Notepad++, the following would work:
Find:
<span class="Heading3-strong">(.*?)</span>
Replace with:
<strong>1</strong>
The 1
is a back reference to the first capturing group (the part between (
and )
) in the regular expression.
add a comment |
My previous post was deleted, so let me try again, with more detail.
In all seriousness, do not use regex on nested markup. It's a recipe for pain.
Although Glorfindel's example works for simple cases, it will fail whenever you run into nested tag sets.
Works:
<span class="Heading3-strong">this is text</span>
... becomes:
<strong>this is text</strong>
This is still well-formed and valid markup.
However, this doesn't work:
<span class="Heading3-strong">this is text <span style="color:red;">with</span> <span style="color:blue;">additional</span> <span style="color:green;">tags</span> in the middle</span>
... becomes:
<strong>this is text <span style="color:red;">with</strong> <span style="color:blue;">additional</span> <span style="color:green;">tags</span> in the middle</span>
This is now malformed markup.
This is an intractable problem for simple regex -- there's just no way to handle nested markup correctly with regex alone. If you need to change tag pairs in any sort of nested tag content, your best bet is to use a tool specifically geared towards markup, such as XSLT or something similar.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1421905%2fi-want-to-replace-html-tags-but-keep-the-text-in-between%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's not clear which program you are using the regex in, but what you're looking for are capturing groups and backreferences.
For example, in Notepad++, the following would work:
Find:
<span class="Heading3-strong">(.*?)</span>
Replace with:
<strong>1</strong>
The 1
is a back reference to the first capturing group (the part between (
and )
) in the regular expression.
add a comment |
It's not clear which program you are using the regex in, but what you're looking for are capturing groups and backreferences.
For example, in Notepad++, the following would work:
Find:
<span class="Heading3-strong">(.*?)</span>
Replace with:
<strong>1</strong>
The 1
is a back reference to the first capturing group (the part between (
and )
) in the regular expression.
add a comment |
It's not clear which program you are using the regex in, but what you're looking for are capturing groups and backreferences.
For example, in Notepad++, the following would work:
Find:
<span class="Heading3-strong">(.*?)</span>
Replace with:
<strong>1</strong>
The 1
is a back reference to the first capturing group (the part between (
and )
) in the regular expression.
It's not clear which program you are using the regex in, but what you're looking for are capturing groups and backreferences.
For example, in Notepad++, the following would work:
Find:
<span class="Heading3-strong">(.*?)</span>
Replace with:
<strong>1</strong>
The 1
is a back reference to the first capturing group (the part between (
and )
) in the regular expression.
answered yesterday
GlorfindelGlorfindel
1,51141220
1,51141220
add a comment |
add a comment |
My previous post was deleted, so let me try again, with more detail.
In all seriousness, do not use regex on nested markup. It's a recipe for pain.
Although Glorfindel's example works for simple cases, it will fail whenever you run into nested tag sets.
Works:
<span class="Heading3-strong">this is text</span>
... becomes:
<strong>this is text</strong>
This is still well-formed and valid markup.
However, this doesn't work:
<span class="Heading3-strong">this is text <span style="color:red;">with</span> <span style="color:blue;">additional</span> <span style="color:green;">tags</span> in the middle</span>
... becomes:
<strong>this is text <span style="color:red;">with</strong> <span style="color:blue;">additional</span> <span style="color:green;">tags</span> in the middle</span>
This is now malformed markup.
This is an intractable problem for simple regex -- there's just no way to handle nested markup correctly with regex alone. If you need to change tag pairs in any sort of nested tag content, your best bet is to use a tool specifically geared towards markup, such as XSLT or something similar.
add a comment |
My previous post was deleted, so let me try again, with more detail.
In all seriousness, do not use regex on nested markup. It's a recipe for pain.
Although Glorfindel's example works for simple cases, it will fail whenever you run into nested tag sets.
Works:
<span class="Heading3-strong">this is text</span>
... becomes:
<strong>this is text</strong>
This is still well-formed and valid markup.
However, this doesn't work:
<span class="Heading3-strong">this is text <span style="color:red;">with</span> <span style="color:blue;">additional</span> <span style="color:green;">tags</span> in the middle</span>
... becomes:
<strong>this is text <span style="color:red;">with</strong> <span style="color:blue;">additional</span> <span style="color:green;">tags</span> in the middle</span>
This is now malformed markup.
This is an intractable problem for simple regex -- there's just no way to handle nested markup correctly with regex alone. If you need to change tag pairs in any sort of nested tag content, your best bet is to use a tool specifically geared towards markup, such as XSLT or something similar.
add a comment |
My previous post was deleted, so let me try again, with more detail.
In all seriousness, do not use regex on nested markup. It's a recipe for pain.
Although Glorfindel's example works for simple cases, it will fail whenever you run into nested tag sets.
Works:
<span class="Heading3-strong">this is text</span>
... becomes:
<strong>this is text</strong>
This is still well-formed and valid markup.
However, this doesn't work:
<span class="Heading3-strong">this is text <span style="color:red;">with</span> <span style="color:blue;">additional</span> <span style="color:green;">tags</span> in the middle</span>
... becomes:
<strong>this is text <span style="color:red;">with</strong> <span style="color:blue;">additional</span> <span style="color:green;">tags</span> in the middle</span>
This is now malformed markup.
This is an intractable problem for simple regex -- there's just no way to handle nested markup correctly with regex alone. If you need to change tag pairs in any sort of nested tag content, your best bet is to use a tool specifically geared towards markup, such as XSLT or something similar.
My previous post was deleted, so let me try again, with more detail.
In all seriousness, do not use regex on nested markup. It's a recipe for pain.
Although Glorfindel's example works for simple cases, it will fail whenever you run into nested tag sets.
Works:
<span class="Heading3-strong">this is text</span>
... becomes:
<strong>this is text</strong>
This is still well-formed and valid markup.
However, this doesn't work:
<span class="Heading3-strong">this is text <span style="color:red;">with</span> <span style="color:blue;">additional</span> <span style="color:green;">tags</span> in the middle</span>
... becomes:
<strong>this is text <span style="color:red;">with</strong> <span style="color:blue;">additional</span> <span style="color:green;">tags</span> in the middle</span>
This is now malformed markup.
This is an intractable problem for simple regex -- there's just no way to handle nested markup correctly with regex alone. If you need to change tag pairs in any sort of nested tag content, your best bet is to use a tool specifically geared towards markup, such as XSLT or something similar.
answered 1 hour ago
Eiríkr ÚtlendiEiríkr Útlendi
1685
1685
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1421905%2fi-want-to-replace-html-tags-but-keep-the-text-in-between%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Parsing HTML with regex is a hard job. See also stackoverflow.com/q/3577641/372239 and stackoverflow.com/a/1732454/372239
– Toto
yesterday
(Since my post was deleted, let's try as a comment.) Using regex to process any kind of nested markup is a very bad idea. If you're not careful, Tony the Pony will come for you. See also the legendary post over on Stack Overflow.
– Eiríkr Útlendi
1 hour ago