regex: reject the match










-2















python 3.5 re version 2.2.1



Toy example:



S1 = 'Arithmetic Return 2018 (%)'
s2 = 'Arithmetic Return 2019 (%)'

p = re.compile(r'(^.*?Arithm.*$)')
w = [re.findall(p, a) for a in [s1, s2]]


  • How can I make sure that I will match only s2 that contains '2019'

  • How can I ignore caps / lower case?









share|improve this question



















  • 1





    Your regex matches any line that has Arithm in it, see ideone.com/tejbbu. What are you trying to achieve?

    – Wiktor Stribiżew
    Nov 14 '18 at 21:15












  • What is so specific about s2 that you want to only match that text?

    – Wiktor Stribiżew
    Nov 14 '18 at 21:16











  • Is your regex supposed to be "any text that contains Arithm followed by 2019"?

    – Patrick Haugh
    Nov 14 '18 at 21:17












  • the year....Essentially I want to match Arithm and NOT 2018. That is I want to reject 2018

    – Cy Bu
    Nov 14 '18 at 21:17







  • 1





    It sounds as if you wanted to use if 'arithm' in s.lower() and '2018' not in s:...

    – Wiktor Stribiżew
    Nov 14 '18 at 21:18
















-2















python 3.5 re version 2.2.1



Toy example:



S1 = 'Arithmetic Return 2018 (%)'
s2 = 'Arithmetic Return 2019 (%)'

p = re.compile(r'(^.*?Arithm.*$)')
w = [re.findall(p, a) for a in [s1, s2]]


  • How can I make sure that I will match only s2 that contains '2019'

  • How can I ignore caps / lower case?









share|improve this question



















  • 1





    Your regex matches any line that has Arithm in it, see ideone.com/tejbbu. What are you trying to achieve?

    – Wiktor Stribiżew
    Nov 14 '18 at 21:15












  • What is so specific about s2 that you want to only match that text?

    – Wiktor Stribiżew
    Nov 14 '18 at 21:16











  • Is your regex supposed to be "any text that contains Arithm followed by 2019"?

    – Patrick Haugh
    Nov 14 '18 at 21:17












  • the year....Essentially I want to match Arithm and NOT 2018. That is I want to reject 2018

    – Cy Bu
    Nov 14 '18 at 21:17







  • 1





    It sounds as if you wanted to use if 'arithm' in s.lower() and '2018' not in s:...

    – Wiktor Stribiżew
    Nov 14 '18 at 21:18














-2












-2








-2








python 3.5 re version 2.2.1



Toy example:



S1 = 'Arithmetic Return 2018 (%)'
s2 = 'Arithmetic Return 2019 (%)'

p = re.compile(r'(^.*?Arithm.*$)')
w = [re.findall(p, a) for a in [s1, s2]]


  • How can I make sure that I will match only s2 that contains '2019'

  • How can I ignore caps / lower case?









share|improve this question
















python 3.5 re version 2.2.1



Toy example:



S1 = 'Arithmetic Return 2018 (%)'
s2 = 'Arithmetic Return 2019 (%)'

p = re.compile(r'(^.*?Arithm.*$)')
w = [re.findall(p, a) for a in [s1, s2]]


  • How can I make sure that I will match only s2 that contains '2019'

  • How can I ignore caps / lower case?






regex python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 21:15







Cy Bu

















asked Nov 14 '18 at 21:12









Cy BuCy Bu

5311819




5311819







  • 1





    Your regex matches any line that has Arithm in it, see ideone.com/tejbbu. What are you trying to achieve?

    – Wiktor Stribiżew
    Nov 14 '18 at 21:15












  • What is so specific about s2 that you want to only match that text?

    – Wiktor Stribiżew
    Nov 14 '18 at 21:16











  • Is your regex supposed to be "any text that contains Arithm followed by 2019"?

    – Patrick Haugh
    Nov 14 '18 at 21:17












  • the year....Essentially I want to match Arithm and NOT 2018. That is I want to reject 2018

    – Cy Bu
    Nov 14 '18 at 21:17







  • 1





    It sounds as if you wanted to use if 'arithm' in s.lower() and '2018' not in s:...

    – Wiktor Stribiżew
    Nov 14 '18 at 21:18













  • 1





    Your regex matches any line that has Arithm in it, see ideone.com/tejbbu. What are you trying to achieve?

    – Wiktor Stribiżew
    Nov 14 '18 at 21:15












  • What is so specific about s2 that you want to only match that text?

    – Wiktor Stribiżew
    Nov 14 '18 at 21:16











  • Is your regex supposed to be "any text that contains Arithm followed by 2019"?

    – Patrick Haugh
    Nov 14 '18 at 21:17












  • the year....Essentially I want to match Arithm and NOT 2018. That is I want to reject 2018

    – Cy Bu
    Nov 14 '18 at 21:17







  • 1





    It sounds as if you wanted to use if 'arithm' in s.lower() and '2018' not in s:...

    – Wiktor Stribiżew
    Nov 14 '18 at 21:18








1




1





Your regex matches any line that has Arithm in it, see ideone.com/tejbbu. What are you trying to achieve?

– Wiktor Stribiżew
Nov 14 '18 at 21:15






Your regex matches any line that has Arithm in it, see ideone.com/tejbbu. What are you trying to achieve?

– Wiktor Stribiżew
Nov 14 '18 at 21:15














What is so specific about s2 that you want to only match that text?

– Wiktor Stribiżew
Nov 14 '18 at 21:16





What is so specific about s2 that you want to only match that text?

– Wiktor Stribiżew
Nov 14 '18 at 21:16













Is your regex supposed to be "any text that contains Arithm followed by 2019"?

– Patrick Haugh
Nov 14 '18 at 21:17






Is your regex supposed to be "any text that contains Arithm followed by 2019"?

– Patrick Haugh
Nov 14 '18 at 21:17














the year....Essentially I want to match Arithm and NOT 2018. That is I want to reject 2018

– Cy Bu
Nov 14 '18 at 21:17






the year....Essentially I want to match Arithm and NOT 2018. That is I want to reject 2018

– Cy Bu
Nov 14 '18 at 21:17





1




1





It sounds as if you wanted to use if 'arithm' in s.lower() and '2018' not in s:...

– Wiktor Stribiżew
Nov 14 '18 at 21:18






It sounds as if you wanted to use if 'arithm' in s.lower() and '2018' not in s:...

– Wiktor Stribiżew
Nov 14 '18 at 21:18













1 Answer
1






active

oldest

votes


















1














You can just add 2019.* to your regex to match a string that contains Arithm (case insensitive through (?i))
followed by 2019 somewhere in the string. Like this: (?i)^.*?Arithm.*2019.*$.



I know it's not javascript but it's handy to see a working example, copied from regex101:




const regex = /^.*?Arithm.*2019.*$/gmi;
const str = `Arithmetic Return 2018 (%)
Arithmetic Return 2019 (%)`;
let m;

while ((m = regex.exec(str)) !== null)
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex)
regex.lastIndex++;


// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) =>
console.log(`Found match, group $groupIndex: $match`);
);





Python:



import re

s1 = 'Arithmetic Return 2018 (%)'
s2 = 'Arithmetic Return 2019 (%)'

p = re.compile(r'(?i)^.*?Arithm.*2019.*$')
w = [re.findall(p, a) for a in [s1, s2]]
print(w)





share|improve this answer




















  • 1





    well, python regexes aren't javascript regexes. In particular //gm don't exist in python

    – Jean-François Fabre
    Nov 14 '18 at 21:19











  • Anyway, it is not what OP needs. Essentially I want to match Arithm and NOT 2018 Nor does this answer How can I ignore caps / lower case?

    – Wiktor Stribiżew
    Nov 14 '18 at 21:22












  • No reason to use compile if you're not going to use the returned object. w = [p.findall(a) for a in [s1, s2]]

    – nicholishen
    Nov 14 '18 at 21:26










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%2f53308791%2fregex-reject-the-match%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can just add 2019.* to your regex to match a string that contains Arithm (case insensitive through (?i))
followed by 2019 somewhere in the string. Like this: (?i)^.*?Arithm.*2019.*$.



I know it's not javascript but it's handy to see a working example, copied from regex101:




const regex = /^.*?Arithm.*2019.*$/gmi;
const str = `Arithmetic Return 2018 (%)
Arithmetic Return 2019 (%)`;
let m;

while ((m = regex.exec(str)) !== null)
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex)
regex.lastIndex++;


// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) =>
console.log(`Found match, group $groupIndex: $match`);
);





Python:



import re

s1 = 'Arithmetic Return 2018 (%)'
s2 = 'Arithmetic Return 2019 (%)'

p = re.compile(r'(?i)^.*?Arithm.*2019.*$')
w = [re.findall(p, a) for a in [s1, s2]]
print(w)





share|improve this answer




















  • 1





    well, python regexes aren't javascript regexes. In particular //gm don't exist in python

    – Jean-François Fabre
    Nov 14 '18 at 21:19











  • Anyway, it is not what OP needs. Essentially I want to match Arithm and NOT 2018 Nor does this answer How can I ignore caps / lower case?

    – Wiktor Stribiżew
    Nov 14 '18 at 21:22












  • No reason to use compile if you're not going to use the returned object. w = [p.findall(a) for a in [s1, s2]]

    – nicholishen
    Nov 14 '18 at 21:26















1














You can just add 2019.* to your regex to match a string that contains Arithm (case insensitive through (?i))
followed by 2019 somewhere in the string. Like this: (?i)^.*?Arithm.*2019.*$.



I know it's not javascript but it's handy to see a working example, copied from regex101:




const regex = /^.*?Arithm.*2019.*$/gmi;
const str = `Arithmetic Return 2018 (%)
Arithmetic Return 2019 (%)`;
let m;

while ((m = regex.exec(str)) !== null)
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex)
regex.lastIndex++;


// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) =>
console.log(`Found match, group $groupIndex: $match`);
);





Python:



import re

s1 = 'Arithmetic Return 2018 (%)'
s2 = 'Arithmetic Return 2019 (%)'

p = re.compile(r'(?i)^.*?Arithm.*2019.*$')
w = [re.findall(p, a) for a in [s1, s2]]
print(w)





share|improve this answer




















  • 1





    well, python regexes aren't javascript regexes. In particular //gm don't exist in python

    – Jean-François Fabre
    Nov 14 '18 at 21:19











  • Anyway, it is not what OP needs. Essentially I want to match Arithm and NOT 2018 Nor does this answer How can I ignore caps / lower case?

    – Wiktor Stribiżew
    Nov 14 '18 at 21:22












  • No reason to use compile if you're not going to use the returned object. w = [p.findall(a) for a in [s1, s2]]

    – nicholishen
    Nov 14 '18 at 21:26













1












1








1







You can just add 2019.* to your regex to match a string that contains Arithm (case insensitive through (?i))
followed by 2019 somewhere in the string. Like this: (?i)^.*?Arithm.*2019.*$.



I know it's not javascript but it's handy to see a working example, copied from regex101:




const regex = /^.*?Arithm.*2019.*$/gmi;
const str = `Arithmetic Return 2018 (%)
Arithmetic Return 2019 (%)`;
let m;

while ((m = regex.exec(str)) !== null)
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex)
regex.lastIndex++;


// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) =>
console.log(`Found match, group $groupIndex: $match`);
);





Python:



import re

s1 = 'Arithmetic Return 2018 (%)'
s2 = 'Arithmetic Return 2019 (%)'

p = re.compile(r'(?i)^.*?Arithm.*2019.*$')
w = [re.findall(p, a) for a in [s1, s2]]
print(w)





share|improve this answer















You can just add 2019.* to your regex to match a string that contains Arithm (case insensitive through (?i))
followed by 2019 somewhere in the string. Like this: (?i)^.*?Arithm.*2019.*$.



I know it's not javascript but it's handy to see a working example, copied from regex101:




const regex = /^.*?Arithm.*2019.*$/gmi;
const str = `Arithmetic Return 2018 (%)
Arithmetic Return 2019 (%)`;
let m;

while ((m = regex.exec(str)) !== null)
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex)
regex.lastIndex++;


// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) =>
console.log(`Found match, group $groupIndex: $match`);
);





Python:



import re

s1 = 'Arithmetic Return 2018 (%)'
s2 = 'Arithmetic Return 2019 (%)'

p = re.compile(r'(?i)^.*?Arithm.*2019.*$')
w = [re.findall(p, a) for a in [s1, s2]]
print(w)





const regex = /^.*?Arithm.*2019.*$/gmi;
const str = `Arithmetic Return 2018 (%)
Arithmetic Return 2019 (%)`;
let m;

while ((m = regex.exec(str)) !== null)
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex)
regex.lastIndex++;


// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) =>
console.log(`Found match, group $groupIndex: $match`);
);





const regex = /^.*?Arithm.*2019.*$/gmi;
const str = `Arithmetic Return 2018 (%)
Arithmetic Return 2019 (%)`;
let m;

while ((m = regex.exec(str)) !== null)
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex)
regex.lastIndex++;


// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) =>
console.log(`Found match, group $groupIndex: $match`);
);






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 21:29

























answered Nov 14 '18 at 21:18









MarkMark

3,70921126




3,70921126







  • 1





    well, python regexes aren't javascript regexes. In particular //gm don't exist in python

    – Jean-François Fabre
    Nov 14 '18 at 21:19











  • Anyway, it is not what OP needs. Essentially I want to match Arithm and NOT 2018 Nor does this answer How can I ignore caps / lower case?

    – Wiktor Stribiżew
    Nov 14 '18 at 21:22












  • No reason to use compile if you're not going to use the returned object. w = [p.findall(a) for a in [s1, s2]]

    – nicholishen
    Nov 14 '18 at 21:26












  • 1





    well, python regexes aren't javascript regexes. In particular //gm don't exist in python

    – Jean-François Fabre
    Nov 14 '18 at 21:19











  • Anyway, it is not what OP needs. Essentially I want to match Arithm and NOT 2018 Nor does this answer How can I ignore caps / lower case?

    – Wiktor Stribiżew
    Nov 14 '18 at 21:22












  • No reason to use compile if you're not going to use the returned object. w = [p.findall(a) for a in [s1, s2]]

    – nicholishen
    Nov 14 '18 at 21:26







1




1





well, python regexes aren't javascript regexes. In particular //gm don't exist in python

– Jean-François Fabre
Nov 14 '18 at 21:19





well, python regexes aren't javascript regexes. In particular //gm don't exist in python

– Jean-François Fabre
Nov 14 '18 at 21:19













Anyway, it is not what OP needs. Essentially I want to match Arithm and NOT 2018 Nor does this answer How can I ignore caps / lower case?

– Wiktor Stribiżew
Nov 14 '18 at 21:22






Anyway, it is not what OP needs. Essentially I want to match Arithm and NOT 2018 Nor does this answer How can I ignore caps / lower case?

– Wiktor Stribiżew
Nov 14 '18 at 21:22














No reason to use compile if you're not going to use the returned object. w = [p.findall(a) for a in [s1, s2]]

– nicholishen
Nov 14 '18 at 21:26





No reason to use compile if you're not going to use the returned object. w = [p.findall(a) for a in [s1, s2]]

– nicholishen
Nov 14 '18 at 21:26



















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%2f53308791%2fregex-reject-the-match%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

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo