Delete Consecutively Repeated String

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I have the following text:



text = "hello","hello","hello","c","a","e","e","hello","hello"


Now I would like to do the following:



Delete every string that is "hello" and repeats itself consecutively.



Result:



text = "hello","c","a","e","e","hello"









share|improve this question

























    up vote
    2
    down vote

    favorite












    I have the following text:



    text = "hello","hello","hello","c","a","e","e","hello","hello"


    Now I would like to do the following:



    Delete every string that is "hello" and repeats itself consecutively.



    Result:



    text = "hello","c","a","e","e","hello"









    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I have the following text:



      text = "hello","hello","hello","c","a","e","e","hello","hello"


      Now I would like to do the following:



      Delete every string that is "hello" and repeats itself consecutively.



      Result:



      text = "hello","c","a","e","e","hello"









      share|improve this question













      I have the following text:



      text = "hello","hello","hello","c","a","e","e","hello","hello"


      Now I would like to do the following:



      Delete every string that is "hello" and repeats itself consecutively.



      Result:



      text = "hello","c","a","e","e","hello"






      string-manipulation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 39 mins ago









      james

      651418




      651418




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          For version 11.3:



          SequenceReplace[text, "hello" .. -> "hello"]


          One approach for the versions older than 11.3:



          Split[text] /. "hello" .. -> "hello" // Flatten





          share|improve this answer






















          • Very nice ! Thanks a lot ! :)
            – james
            18 mins ago










          • @james With pleasure :).
            – Î‘λέξανδρος Ζεγγ
            16 mins ago

















          up vote
          2
          down vote













          Also



          ReplaceRepeated[text, a___, Longest["hello" ..], b___ :> a, "hello", b]



          "hello", "c", "a", "e", "e", "hello"







          share|improve this answer




















          • This also works. But why some codes (a___, Longest, b___) in my notebook turn red?
            – Î‘λέξανδρος Ζεγγ
            12 mins ago











          • @ΑλέξανδροςΖεγγ, i don't get that in version 9 or version 11.3.
            – kglr
            11 mins ago










          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "387"
          ;
          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183977%2fdelete-consecutively-repeated-string%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          For version 11.3:



          SequenceReplace[text, "hello" .. -> "hello"]


          One approach for the versions older than 11.3:



          Split[text] /. "hello" .. -> "hello" // Flatten





          share|improve this answer






















          • Very nice ! Thanks a lot ! :)
            – james
            18 mins ago










          • @james With pleasure :).
            – Î‘λέξανδρος Ζεγγ
            16 mins ago














          up vote
          2
          down vote



          accepted










          For version 11.3:



          SequenceReplace[text, "hello" .. -> "hello"]


          One approach for the versions older than 11.3:



          Split[text] /. "hello" .. -> "hello" // Flatten





          share|improve this answer






















          • Very nice ! Thanks a lot ! :)
            – james
            18 mins ago










          • @james With pleasure :).
            – Î‘λέξανδρος Ζεγγ
            16 mins ago












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          For version 11.3:



          SequenceReplace[text, "hello" .. -> "hello"]


          One approach for the versions older than 11.3:



          Split[text] /. "hello" .. -> "hello" // Flatten





          share|improve this answer














          For version 11.3:



          SequenceReplace[text, "hello" .. -> "hello"]


          One approach for the versions older than 11.3:



          Split[text] /. "hello" .. -> "hello" // Flatten






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 31 mins ago

























          answered 36 mins ago









          Αλέξανδρος Ζεγγ

          2,5591826




          2,5591826











          • Very nice ! Thanks a lot ! :)
            – james
            18 mins ago










          • @james With pleasure :).
            – Î‘λέξανδρος Ζεγγ
            16 mins ago
















          • Very nice ! Thanks a lot ! :)
            – james
            18 mins ago










          • @james With pleasure :).
            – Î‘λέξανδρος Ζεγγ
            16 mins ago















          Very nice ! Thanks a lot ! :)
          – james
          18 mins ago




          Very nice ! Thanks a lot ! :)
          – james
          18 mins ago












          @james With pleasure :).
          – Î‘λέξανδρος Ζεγγ
          16 mins ago




          @james With pleasure :).
          – Î‘λέξανδρος Ζεγγ
          16 mins ago










          up vote
          2
          down vote













          Also



          ReplaceRepeated[text, a___, Longest["hello" ..], b___ :> a, "hello", b]



          "hello", "c", "a", "e", "e", "hello"







          share|improve this answer




















          • This also works. But why some codes (a___, Longest, b___) in my notebook turn red?
            – Î‘λέξανδρος Ζεγγ
            12 mins ago











          • @ΑλέξανδροςΖεγγ, i don't get that in version 9 or version 11.3.
            – kglr
            11 mins ago














          up vote
          2
          down vote













          Also



          ReplaceRepeated[text, a___, Longest["hello" ..], b___ :> a, "hello", b]



          "hello", "c", "a", "e", "e", "hello"







          share|improve this answer




















          • This also works. But why some codes (a___, Longest, b___) in my notebook turn red?
            – Î‘λέξανδρος Ζεγγ
            12 mins ago











          • @ΑλέξανδροςΖεγγ, i don't get that in version 9 or version 11.3.
            – kglr
            11 mins ago












          up vote
          2
          down vote










          up vote
          2
          down vote









          Also



          ReplaceRepeated[text, a___, Longest["hello" ..], b___ :> a, "hello", b]



          "hello", "c", "a", "e", "e", "hello"







          share|improve this answer












          Also



          ReplaceRepeated[text, a___, Longest["hello" ..], b___ :> a, "hello", b]



          "hello", "c", "a", "e", "e", "hello"








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 15 mins ago









          kglr

          165k8188388




          165k8188388











          • This also works. But why some codes (a___, Longest, b___) in my notebook turn red?
            – Î‘λέξανδρος Ζεγγ
            12 mins ago











          • @ΑλέξανδροςΖεγγ, i don't get that in version 9 or version 11.3.
            – kglr
            11 mins ago
















          • This also works. But why some codes (a___, Longest, b___) in my notebook turn red?
            – Î‘λέξανδρος Ζεγγ
            12 mins ago











          • @ΑλέξανδροςΖεγγ, i don't get that in version 9 or version 11.3.
            – kglr
            11 mins ago















          This also works. But why some codes (a___, Longest, b___) in my notebook turn red?
          – Î‘λέξανδρος Ζεγγ
          12 mins ago





          This also works. But why some codes (a___, Longest, b___) in my notebook turn red?
          – Î‘λέξανδρος Ζεγγ
          12 mins ago













          @ΑλέξανδροςΖεγγ, i don't get that in version 9 or version 11.3.
          – kglr
          11 mins ago




          @ΑλέξανδροςΖεγγ, i don't get that in version 9 or version 11.3.
          – kglr
          11 mins ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183977%2fdelete-consecutively-repeated-string%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery