Regex for selecting words ending in 'ing' unless










1














I want to select words ending in with a regular expression, but I want exclude words that end in thing. For example:



everything
running
catching
nothing


Of these words, running and catching should be selected, everything and nothing should be excluded.



I've tried the following:



.+ing$


But that selects everything. I'm thinking look aheads/look arounds could be the solution, but I haven't been able to get one that works.



Solutions that work in Python or R would be helpful.










share|improve this question





















  • Use bw*ingb(?<!thing) or bw*(?<!th)ingb
    – Wiktor Stribiżew
    Nov 12 '18 at 21:11
















1














I want to select words ending in with a regular expression, but I want exclude words that end in thing. For example:



everything
running
catching
nothing


Of these words, running and catching should be selected, everything and nothing should be excluded.



I've tried the following:



.+ing$


But that selects everything. I'm thinking look aheads/look arounds could be the solution, but I haven't been able to get one that works.



Solutions that work in Python or R would be helpful.










share|improve this question





















  • Use bw*ingb(?<!thing) or bw*(?<!th)ingb
    – Wiktor Stribiżew
    Nov 12 '18 at 21:11














1












1








1







I want to select words ending in with a regular expression, but I want exclude words that end in thing. For example:



everything
running
catching
nothing


Of these words, running and catching should be selected, everything and nothing should be excluded.



I've tried the following:



.+ing$


But that selects everything. I'm thinking look aheads/look arounds could be the solution, but I haven't been able to get one that works.



Solutions that work in Python or R would be helpful.










share|improve this question













I want to select words ending in with a regular expression, but I want exclude words that end in thing. For example:



everything
running
catching
nothing


Of these words, running and catching should be selected, everything and nothing should be excluded.



I've tried the following:



.+ing$


But that selects everything. I'm thinking look aheads/look arounds could be the solution, but I haven't been able to get one that works.



Solutions that work in Python or R would be helpful.







regex regex-negation regex-lookarounds






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 '18 at 21:08









Todd Shannon

537




537











  • Use bw*ingb(?<!thing) or bw*(?<!th)ingb
    – Wiktor Stribiżew
    Nov 12 '18 at 21:11

















  • Use bw*ingb(?<!thing) or bw*(?<!th)ingb
    – Wiktor Stribiżew
    Nov 12 '18 at 21:11
















Use bw*ingb(?<!thing) or bw*(?<!th)ingb
– Wiktor Stribiżew
Nov 12 '18 at 21:11





Use bw*ingb(?<!thing) or bw*(?<!th)ingb
– Wiktor Stribiżew
Nov 12 '18 at 21:11













3 Answers
3






active

oldest

votes


















3














In python you can use negative lookbehind assertion as this:



^.*(?<!th)ing$


RegEx Demo



(?<!th) is negative lookbehind expression that will fail the match if th comes before ing at the end of string.



Note that if you are matching words that are not on separate lines then instead of anchors use word boundaries as:



w+(?<!th)ingb





share|improve this answer




























    2














    Something like bw+(?<!th)ingb maybe.






    share|improve this answer




























      2














      You might also use a negative lookahead (?! to assert that what is on the right is not 0+ times a word character followed by thing and a word boundary:



      b(?!w*thingb)w*ingb



      Regex demo | Python demo






      share|improve this answer






















      • Think you need to add ing to the end of your regex so that it does not match words that do not end in "ing".
        – benvc
        Nov 12 '18 at 21:17










      • @benvc You are correct, thank you!
        – The fourth bird
        Nov 12 '18 at 21:21










      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      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%2fstackoverflow.com%2fquestions%2f53270128%2fregex-for-selecting-words-ending-in-ing-unless%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      In python you can use negative lookbehind assertion as this:



      ^.*(?<!th)ing$


      RegEx Demo



      (?<!th) is negative lookbehind expression that will fail the match if th comes before ing at the end of string.



      Note that if you are matching words that are not on separate lines then instead of anchors use word boundaries as:



      w+(?<!th)ingb





      share|improve this answer

























        3














        In python you can use negative lookbehind assertion as this:



        ^.*(?<!th)ing$


        RegEx Demo



        (?<!th) is negative lookbehind expression that will fail the match if th comes before ing at the end of string.



        Note that if you are matching words that are not on separate lines then instead of anchors use word boundaries as:



        w+(?<!th)ingb





        share|improve this answer























          3












          3








          3






          In python you can use negative lookbehind assertion as this:



          ^.*(?<!th)ing$


          RegEx Demo



          (?<!th) is negative lookbehind expression that will fail the match if th comes before ing at the end of string.



          Note that if you are matching words that are not on separate lines then instead of anchors use word boundaries as:



          w+(?<!th)ingb





          share|improve this answer












          In python you can use negative lookbehind assertion as this:



          ^.*(?<!th)ing$


          RegEx Demo



          (?<!th) is negative lookbehind expression that will fail the match if th comes before ing at the end of string.



          Note that if you are matching words that are not on separate lines then instead of anchors use word boundaries as:



          w+(?<!th)ingb






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 '18 at 21:11









          anubhava

          520k46316390




          520k46316390























              2














              Something like bw+(?<!th)ingb maybe.






              share|improve this answer

























                2














                Something like bw+(?<!th)ingb maybe.






                share|improve this answer























                  2












                  2








                  2






                  Something like bw+(?<!th)ingb maybe.






                  share|improve this answer












                  Something like bw+(?<!th)ingb maybe.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 12 '18 at 21:11









                  sln

                  26.3k31636




                  26.3k31636





















                      2














                      You might also use a negative lookahead (?! to assert that what is on the right is not 0+ times a word character followed by thing and a word boundary:



                      b(?!w*thingb)w*ingb



                      Regex demo | Python demo






                      share|improve this answer






















                      • Think you need to add ing to the end of your regex so that it does not match words that do not end in "ing".
                        – benvc
                        Nov 12 '18 at 21:17










                      • @benvc You are correct, thank you!
                        – The fourth bird
                        Nov 12 '18 at 21:21















                      2














                      You might also use a negative lookahead (?! to assert that what is on the right is not 0+ times a word character followed by thing and a word boundary:



                      b(?!w*thingb)w*ingb



                      Regex demo | Python demo






                      share|improve this answer






















                      • Think you need to add ing to the end of your regex so that it does not match words that do not end in "ing".
                        – benvc
                        Nov 12 '18 at 21:17










                      • @benvc You are correct, thank you!
                        – The fourth bird
                        Nov 12 '18 at 21:21













                      2












                      2








                      2






                      You might also use a negative lookahead (?! to assert that what is on the right is not 0+ times a word character followed by thing and a word boundary:



                      b(?!w*thingb)w*ingb



                      Regex demo | Python demo






                      share|improve this answer














                      You might also use a negative lookahead (?! to assert that what is on the right is not 0+ times a word character followed by thing and a word boundary:



                      b(?!w*thingb)w*ingb



                      Regex demo | Python demo







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 12 '18 at 21:48

























                      answered Nov 12 '18 at 21:15









                      The fourth bird

                      20.8k71326




                      20.8k71326











                      • Think you need to add ing to the end of your regex so that it does not match words that do not end in "ing".
                        – benvc
                        Nov 12 '18 at 21:17










                      • @benvc You are correct, thank you!
                        – The fourth bird
                        Nov 12 '18 at 21:21
















                      • Think you need to add ing to the end of your regex so that it does not match words that do not end in "ing".
                        – benvc
                        Nov 12 '18 at 21:17










                      • @benvc You are correct, thank you!
                        – The fourth bird
                        Nov 12 '18 at 21:21















                      Think you need to add ing to the end of your regex so that it does not match words that do not end in "ing".
                      – benvc
                      Nov 12 '18 at 21:17




                      Think you need to add ing to the end of your regex so that it does not match words that do not end in "ing".
                      – benvc
                      Nov 12 '18 at 21:17












                      @benvc You are correct, thank you!
                      – The fourth bird
                      Nov 12 '18 at 21:21




                      @benvc You are correct, thank you!
                      – The fourth bird
                      Nov 12 '18 at 21:21

















                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


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





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2fstackoverflow.com%2fquestions%2f53270128%2fregex-for-selecting-words-ending-in-ing-unless%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







                      這個網誌中的熱門文章

                      How to read a connectionString WITH PROVIDER in .NET Core?

                      Node.js Script on GitHub Pages or Amazon S3

                      Museum of Modern and Contemporary Art of Trento and Rovereto