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;
}







0















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...










share|improve this question




















  • 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


















0















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...










share|improve this question




















  • 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














0












0








0








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...










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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










2 Answers
2






active

oldest

votes


















0














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.






share|improve this answer































    0














    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.






    share|improve this answer
























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      0














      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.






      share|improve this answer




























        0














        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.






        share|improve this answer


























          0












          0








          0







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          GlorfindelGlorfindel

          1,51141220




          1,51141220

























              0














              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.






              share|improve this answer




























                0














                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.






                share|improve this answer


























                  0












                  0








                  0







                  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.






                  share|improve this answer













                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 1 hour ago









                  Eiríkr ÚtlendiEiríkr Útlendi

                  1685




                  1685






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

                      Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

                      Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...