Using DeleteCases to match a string pattern

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











up vote
2
down vote

favorite












I am trying to remove all of the elements from a list that contain the characters "err" in that order.



I expect the following code to return an empty list:



DeleteCases["Aerr", __ ~~ "err"]


However it fails to recognize the pattern and will return the full List. What am I missing in the documentation for patterns? Perhaps it is an issue with DeleteCases, as I can use StringMatchQ to identify that the patterns match.



StringMatchQ["Aerr", __ ~~ "err"]


Returns True.










share|improve this question









New contributor




Karl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    2
    down vote

    favorite












    I am trying to remove all of the elements from a list that contain the characters "err" in that order.



    I expect the following code to return an empty list:



    DeleteCases["Aerr", __ ~~ "err"]


    However it fails to recognize the pattern and will return the full List. What am I missing in the documentation for patterns? Perhaps it is an issue with DeleteCases, as I can use StringMatchQ to identify that the patterns match.



    StringMatchQ["Aerr", __ ~~ "err"]


    Returns True.










    share|improve this question









    New contributor




    Karl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I am trying to remove all of the elements from a list that contain the characters "err" in that order.



      I expect the following code to return an empty list:



      DeleteCases["Aerr", __ ~~ "err"]


      However it fails to recognize the pattern and will return the full List. What am I missing in the documentation for patterns? Perhaps it is an issue with DeleteCases, as I can use StringMatchQ to identify that the patterns match.



      StringMatchQ["Aerr", __ ~~ "err"]


      Returns True.










      share|improve this question









      New contributor




      Karl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am trying to remove all of the elements from a list that contain the characters "err" in that order.



      I expect the following code to return an empty list:



      DeleteCases["Aerr", __ ~~ "err"]


      However it fails to recognize the pattern and will return the full List. What am I missing in the documentation for patterns? Perhaps it is an issue with DeleteCases, as I can use StringMatchQ to identify that the patterns match.



      StringMatchQ["Aerr", __ ~~ "err"]


      Returns True.







      pattern-matching filtering






      share|improve this question









      New contributor




      Karl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Karl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 14 mins ago









      Carl Woll

      63.2k282163




      63.2k282163






      New contributor




      Karl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 29 mins ago









      Karl

      113




      113




      New contributor




      Karl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Karl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Karl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          First note the FullForm of your pattern:



          __ ~~ "err" //FullForm



          StringExpression[BlankSequence,"err"]




          The pattern is a StringExpression, so you must use a string function, e.g., StringMatchQ instead of DeleteCases, which is expecting a normal pattern. Here are some other possibilities:



          list = "Aerr";

          Select[list, Not @* StringMatchQ[__ ~~ "err"]]
          Pick[list, StringMatchQ[list, __ ~~ "err"], False]











          share|improve this answer



























            up vote
            1
            down vote













            DeleteCases["Aerr", _?(StringMatchQ[ "*err"]) ]






            For versions prior to version 10:



            DeleteCases["Aerr", _?(StringMatchQ[#, "*err"] &)]









            share|improve this answer






















            • While I appreciate the working example, I would have loved further explanation of how it works. I've gathered that the "?" syntax is a pattern test, but how does the "_" pattern which is for a single character match "Aerr"? Also, is it a bug that the code in my original question didn't work, or a misunderstanding of how to use patterns?
              – Karl
              9 mins ago










            • @Karl, please see Carl' Woll's answer for a detailed explanation.
              – kglr
              5 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: "",
            imageUploader:
            brandingHtml: "",
            contentPolicyHtml: "",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );






            Karl is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184973%2fusing-deletecases-to-match-a-string-pattern%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













            First note the FullForm of your pattern:



            __ ~~ "err" //FullForm



            StringExpression[BlankSequence,"err"]




            The pattern is a StringExpression, so you must use a string function, e.g., StringMatchQ instead of DeleteCases, which is expecting a normal pattern. Here are some other possibilities:



            list = "Aerr";

            Select[list, Not @* StringMatchQ[__ ~~ "err"]]
            Pick[list, StringMatchQ[list, __ ~~ "err"], False]











            share|improve this answer
























              up vote
              2
              down vote













              First note the FullForm of your pattern:



              __ ~~ "err" //FullForm



              StringExpression[BlankSequence,"err"]




              The pattern is a StringExpression, so you must use a string function, e.g., StringMatchQ instead of DeleteCases, which is expecting a normal pattern. Here are some other possibilities:



              list = "Aerr";

              Select[list, Not @* StringMatchQ[__ ~~ "err"]]
              Pick[list, StringMatchQ[list, __ ~~ "err"], False]











              share|improve this answer






















                up vote
                2
                down vote










                up vote
                2
                down vote









                First note the FullForm of your pattern:



                __ ~~ "err" //FullForm



                StringExpression[BlankSequence,"err"]




                The pattern is a StringExpression, so you must use a string function, e.g., StringMatchQ instead of DeleteCases, which is expecting a normal pattern. Here are some other possibilities:



                list = "Aerr";

                Select[list, Not @* StringMatchQ[__ ~~ "err"]]
                Pick[list, StringMatchQ[list, __ ~~ "err"], False]











                share|improve this answer












                First note the FullForm of your pattern:



                __ ~~ "err" //FullForm



                StringExpression[BlankSequence,"err"]




                The pattern is a StringExpression, so you must use a string function, e.g., StringMatchQ instead of DeleteCases, which is expecting a normal pattern. Here are some other possibilities:



                list = "Aerr";

                Select[list, Not @* StringMatchQ[__ ~~ "err"]]
                Pick[list, StringMatchQ[list, __ ~~ "err"], False]












                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 10 mins ago









                Carl Woll

                63.2k282163




                63.2k282163




















                    up vote
                    1
                    down vote













                    DeleteCases["Aerr", _?(StringMatchQ[ "*err"]) ]






                    For versions prior to version 10:



                    DeleteCases["Aerr", _?(StringMatchQ[#, "*err"] &)]









                    share|improve this answer






















                    • While I appreciate the working example, I would have loved further explanation of how it works. I've gathered that the "?" syntax is a pattern test, but how does the "_" pattern which is for a single character match "Aerr"? Also, is it a bug that the code in my original question didn't work, or a misunderstanding of how to use patterns?
                      – Karl
                      9 mins ago










                    • @Karl, please see Carl' Woll's answer for a detailed explanation.
                      – kglr
                      5 mins ago














                    up vote
                    1
                    down vote













                    DeleteCases["Aerr", _?(StringMatchQ[ "*err"]) ]






                    For versions prior to version 10:



                    DeleteCases["Aerr", _?(StringMatchQ[#, "*err"] &)]









                    share|improve this answer






















                    • While I appreciate the working example, I would have loved further explanation of how it works. I've gathered that the "?" syntax is a pattern test, but how does the "_" pattern which is for a single character match "Aerr"? Also, is it a bug that the code in my original question didn't work, or a misunderstanding of how to use patterns?
                      – Karl
                      9 mins ago










                    • @Karl, please see Carl' Woll's answer for a detailed explanation.
                      – kglr
                      5 mins ago












                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    DeleteCases["Aerr", _?(StringMatchQ[ "*err"]) ]






                    For versions prior to version 10:



                    DeleteCases["Aerr", _?(StringMatchQ[#, "*err"] &)]









                    share|improve this answer














                    DeleteCases["Aerr", _?(StringMatchQ[ "*err"]) ]






                    For versions prior to version 10:



                    DeleteCases["Aerr", _?(StringMatchQ[#, "*err"] &)]










                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 12 mins ago

























                    answered 25 mins ago









                    kglr

                    168k8192395




                    168k8192395











                    • While I appreciate the working example, I would have loved further explanation of how it works. I've gathered that the "?" syntax is a pattern test, but how does the "_" pattern which is for a single character match "Aerr"? Also, is it a bug that the code in my original question didn't work, or a misunderstanding of how to use patterns?
                      – Karl
                      9 mins ago










                    • @Karl, please see Carl' Woll's answer for a detailed explanation.
                      – kglr
                      5 mins ago
















                    • While I appreciate the working example, I would have loved further explanation of how it works. I've gathered that the "?" syntax is a pattern test, but how does the "_" pattern which is for a single character match "Aerr"? Also, is it a bug that the code in my original question didn't work, or a misunderstanding of how to use patterns?
                      – Karl
                      9 mins ago










                    • @Karl, please see Carl' Woll's answer for a detailed explanation.
                      – kglr
                      5 mins ago















                    While I appreciate the working example, I would have loved further explanation of how it works. I've gathered that the "?" syntax is a pattern test, but how does the "_" pattern which is for a single character match "Aerr"? Also, is it a bug that the code in my original question didn't work, or a misunderstanding of how to use patterns?
                    – Karl
                    9 mins ago




                    While I appreciate the working example, I would have loved further explanation of how it works. I've gathered that the "?" syntax is a pattern test, but how does the "_" pattern which is for a single character match "Aerr"? Also, is it a bug that the code in my original question didn't work, or a misunderstanding of how to use patterns?
                    – Karl
                    9 mins ago












                    @Karl, please see Carl' Woll's answer for a detailed explanation.
                    – kglr
                    5 mins ago




                    @Karl, please see Carl' Woll's answer for a detailed explanation.
                    – kglr
                    5 mins ago










                    Karl is a new contributor. Be nice, and check out our Code of Conduct.









                     

                    draft saved


                    draft discarded


















                    Karl is a new contributor. Be nice, and check out our Code of Conduct.












                    Karl is a new contributor. Be nice, and check out our Code of Conduct.











                    Karl is a new contributor. Be nice, and check out our Code of Conduct.













                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184973%2fusing-deletecases-to-match-a-string-pattern%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?