Regex search failsA comprehensive regex for phone number validationHow to “inverse match” with regex?How to import a module given its name?How to return multiple values from a function?Converting user input string to regular expressionRegEx match open tags except XHTML self-contained tagsPython progression path - From apprentice to guruGreedy vs. Reluctant vs. Possessive QuantifiersReplace only some groups with RegexGrep regex NOT containing string

Subtables with equal width?

How do photons get into the eyes?

Does an ice chest packed full of frozen food need ice?

Building a road to escape Earth's gravity by making a pyramid on Antartica

SF novella separating the dumb majority from the intelligent part of mankind

What is the advantage of carrying a tripod and ND-filters when you could use image stacking instead?

Why don’t airliners have temporary liveries?

Should an arbiter claim draw at a K+R vs K+R endgame?

Do you need type ratings for private flying?

What do we gain with higher order logics?

What are the peak hours for public transportation in Paris?

Smooth switching between 12v batteries, with toggle switch

Why does the Schrödinger equation work so well for the Hydrogen atom despite the relativistic boundary at the nucleus?

What risks are there when you clear your cookies instead of logging off?

How Can I Tell The Difference Between Unmarked Sugar and Stevia?

Are "living" organ banks practical?

Why doesn’t a normal window produce an apparent rainbow?

How would a aircraft visually signal in distress?

What's up with this leaf?

Does the "6 seconds per round" rule apply to speaking/roleplaying during combat situations?

Is any name of Vishnu Siva?

How to make a setting relevant?

2.8 is missing the Carve option in the Boolean Modifier

What's the right way to purge recursively with apt?



Regex search fails


A comprehensive regex for phone number validationHow to “inverse match” with regex?How to import a module given its name?How to return multiple values from a function?Converting user input string to regular expressionRegEx match open tags except XHTML self-contained tagsPython progression path - From apprentice to guruGreedy vs. Reluctant vs. Possessive QuantifiersReplace only some groups with RegexGrep regex NOT containing string






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm using boolean logic for my regex search but it's not working. Specifically, the "and not" part of the expression is not working.



Example: Gi3/3 should match, but Gi3/3(P) should NOT match.



for line in infile:
int = re.search(r"Gid/.+", line, flags=re.IGNORECASE) or re.search(r"Ethd/.+", line) and not re.search(r"^Gid/.+(P)$", line)


When above code is executed, I see matches on Gi3/3(P) and I don't expect this.










share|improve this question






























    0















    I'm using boolean logic for my regex search but it's not working. Specifically, the "and not" part of the expression is not working.



    Example: Gi3/3 should match, but Gi3/3(P) should NOT match.



    for line in infile:
    int = re.search(r"Gid/.+", line, flags=re.IGNORECASE) or re.search(r"Ethd/.+", line) and not re.search(r"^Gid/.+(P)$", line)


    When above code is executed, I see matches on Gi3/3(P) and I don't expect this.










    share|improve this question


























      0












      0








      0








      I'm using boolean logic for my regex search but it's not working. Specifically, the "and not" part of the expression is not working.



      Example: Gi3/3 should match, but Gi3/3(P) should NOT match.



      for line in infile:
      int = re.search(r"Gid/.+", line, flags=re.IGNORECASE) or re.search(r"Ethd/.+", line) and not re.search(r"^Gid/.+(P)$", line)


      When above code is executed, I see matches on Gi3/3(P) and I don't expect this.










      share|improve this question
















      I'm using boolean logic for my regex search but it's not working. Specifically, the "and not" part of the expression is not working.



      Example: Gi3/3 should match, but Gi3/3(P) should NOT match.



      for line in infile:
      int = re.search(r"Gid/.+", line, flags=re.IGNORECASE) or re.search(r"Ethd/.+", line) and not re.search(r"^Gid/.+(P)$", line)


      When above code is executed, I see matches on Gi3/3(P) and I don't expect this.







      python regex python-3.x






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 17:07









      C. Peck

      960324




      960324










      asked Mar 24 at 15:32









      Chuck SlaytonChuck Slayton

      535




      535






















          2 Answers
          2






          active

          oldest

          votes


















          -1














          remove '+' from your regex



          for line in infile:
          int = re.search(r"Gid/.", line, flags=re.IGNORECASE) or re.search(r"Ethd/.", line) and not re.search(r"^Gid/.(P)$", line)





          share|improve this answer























          • You know, funny thing is your solution actually worked, but whoever voted you down probably would have liked to have seen the optimal answer.

            – FailSafe
            Mar 25 at 5:59











          • My intention was to keep your logic same.

            – Sharif Chowdhury
            Mar 25 at 6:01











          • Trust me, I know. Personally, some people here get a bit of pleasure pushing that downvote button. I didn't and wouldn't have - I see exactly what you did and I personally like it, but I have to acknowledge that the regex would still easily be broken with little nuance.

            – FailSafe
            Mar 25 at 6:03



















          1














          You can have one reguar expression with lookahead that is catching all three conditions:



          re.search(r"(Gi|Eth)d/d+(?=>D|$)", line, flags=re.IGNORECASE)





          share|improve this answer























          • The question was kind of badly asked especially in light of the accepted answer

            – FailSafe
            Mar 25 at 6:01











          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%2f55325423%2fregex-search-fails%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









          -1














          remove '+' from your regex



          for line in infile:
          int = re.search(r"Gid/.", line, flags=re.IGNORECASE) or re.search(r"Ethd/.", line) and not re.search(r"^Gid/.(P)$", line)





          share|improve this answer























          • You know, funny thing is your solution actually worked, but whoever voted you down probably would have liked to have seen the optimal answer.

            – FailSafe
            Mar 25 at 5:59











          • My intention was to keep your logic same.

            – Sharif Chowdhury
            Mar 25 at 6:01











          • Trust me, I know. Personally, some people here get a bit of pleasure pushing that downvote button. I didn't and wouldn't have - I see exactly what you did and I personally like it, but I have to acknowledge that the regex would still easily be broken with little nuance.

            – FailSafe
            Mar 25 at 6:03
















          -1














          remove '+' from your regex



          for line in infile:
          int = re.search(r"Gid/.", line, flags=re.IGNORECASE) or re.search(r"Ethd/.", line) and not re.search(r"^Gid/.(P)$", line)





          share|improve this answer























          • You know, funny thing is your solution actually worked, but whoever voted you down probably would have liked to have seen the optimal answer.

            – FailSafe
            Mar 25 at 5:59











          • My intention was to keep your logic same.

            – Sharif Chowdhury
            Mar 25 at 6:01











          • Trust me, I know. Personally, some people here get a bit of pleasure pushing that downvote button. I didn't and wouldn't have - I see exactly what you did and I personally like it, but I have to acknowledge that the regex would still easily be broken with little nuance.

            – FailSafe
            Mar 25 at 6:03














          -1












          -1








          -1







          remove '+' from your regex



          for line in infile:
          int = re.search(r"Gid/.", line, flags=re.IGNORECASE) or re.search(r"Ethd/.", line) and not re.search(r"^Gid/.(P)$", line)





          share|improve this answer













          remove '+' from your regex



          for line in infile:
          int = re.search(r"Gid/.", line, flags=re.IGNORECASE) or re.search(r"Ethd/.", line) and not re.search(r"^Gid/.(P)$", line)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 24 at 16:32









          Sharif ChowdhurySharif Chowdhury

          1345




          1345












          • You know, funny thing is your solution actually worked, but whoever voted you down probably would have liked to have seen the optimal answer.

            – FailSafe
            Mar 25 at 5:59











          • My intention was to keep your logic same.

            – Sharif Chowdhury
            Mar 25 at 6:01











          • Trust me, I know. Personally, some people here get a bit of pleasure pushing that downvote button. I didn't and wouldn't have - I see exactly what you did and I personally like it, but I have to acknowledge that the regex would still easily be broken with little nuance.

            – FailSafe
            Mar 25 at 6:03


















          • You know, funny thing is your solution actually worked, but whoever voted you down probably would have liked to have seen the optimal answer.

            – FailSafe
            Mar 25 at 5:59











          • My intention was to keep your logic same.

            – Sharif Chowdhury
            Mar 25 at 6:01











          • Trust me, I know. Personally, some people here get a bit of pleasure pushing that downvote button. I didn't and wouldn't have - I see exactly what you did and I personally like it, but I have to acknowledge that the regex would still easily be broken with little nuance.

            – FailSafe
            Mar 25 at 6:03

















          You know, funny thing is your solution actually worked, but whoever voted you down probably would have liked to have seen the optimal answer.

          – FailSafe
          Mar 25 at 5:59





          You know, funny thing is your solution actually worked, but whoever voted you down probably would have liked to have seen the optimal answer.

          – FailSafe
          Mar 25 at 5:59













          My intention was to keep your logic same.

          – Sharif Chowdhury
          Mar 25 at 6:01





          My intention was to keep your logic same.

          – Sharif Chowdhury
          Mar 25 at 6:01













          Trust me, I know. Personally, some people here get a bit of pleasure pushing that downvote button. I didn't and wouldn't have - I see exactly what you did and I personally like it, but I have to acknowledge that the regex would still easily be broken with little nuance.

          – FailSafe
          Mar 25 at 6:03






          Trust me, I know. Personally, some people here get a bit of pleasure pushing that downvote button. I didn't and wouldn't have - I see exactly what you did and I personally like it, but I have to acknowledge that the regex would still easily be broken with little nuance.

          – FailSafe
          Mar 25 at 6:03














          1














          You can have one reguar expression with lookahead that is catching all three conditions:



          re.search(r"(Gi|Eth)d/d+(?=>D|$)", line, flags=re.IGNORECASE)





          share|improve this answer























          • The question was kind of badly asked especially in light of the accepted answer

            – FailSafe
            Mar 25 at 6:01















          1














          You can have one reguar expression with lookahead that is catching all three conditions:



          re.search(r"(Gi|Eth)d/d+(?=>D|$)", line, flags=re.IGNORECASE)





          share|improve this answer























          • The question was kind of badly asked especially in light of the accepted answer

            – FailSafe
            Mar 25 at 6:01













          1












          1








          1







          You can have one reguar expression with lookahead that is catching all three conditions:



          re.search(r"(Gi|Eth)d/d+(?=>D|$)", line, flags=re.IGNORECASE)





          share|improve this answer













          You can have one reguar expression with lookahead that is catching all three conditions:



          re.search(r"(Gi|Eth)d/d+(?=>D|$)", line, flags=re.IGNORECASE)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 24 at 20:00









          DYZDYZ

          30k62354




          30k62354












          • The question was kind of badly asked especially in light of the accepted answer

            – FailSafe
            Mar 25 at 6:01

















          • The question was kind of badly asked especially in light of the accepted answer

            – FailSafe
            Mar 25 at 6:01
















          The question was kind of badly asked especially in light of the accepted answer

          – FailSafe
          Mar 25 at 6:01





          The question was kind of badly asked especially in light of the accepted answer

          – FailSafe
          Mar 25 at 6:01

















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55325423%2fregex-search-fails%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현