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;
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
add a comment |
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
add a comment |
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
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
python regex python-3.x
edited Mar 24 at 17:07
C. Peck
960324
960324
asked Mar 24 at 15:32
Chuck SlaytonChuck Slayton
535
535
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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)
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
add a comment |
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)
The question was kind of badly asked especially in light of the accepted answer
– FailSafe
Mar 25 at 6:01
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
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
add a comment |
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)
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
add a comment |
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)
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)
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
add a comment |
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
add a comment |
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)
The question was kind of badly asked especially in light of the accepted answer
– FailSafe
Mar 25 at 6:01
add a comment |
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)
The question was kind of badly asked especially in light of the accepted answer
– FailSafe
Mar 25 at 6:01
add a comment |
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)
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)
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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