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

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript