python - Match if word does not appear before another word in regex -


i'm trying write regex matches if keyword not appear somewhere in string before stopword.

example:

this should not match anything:

aaa: ok

bbb: failed

ccc: ok

stopword

random text ok failed random text

this should match:

aaa: ok

bbb: ok

ccc: ok

stopword

random text ok failed random text

i guess should use negative check ^(?!.*failed) how stop checking @ [stopword]?

i'm trying pythons regex engine if matters.

edit: sorry being unclear. yes, it's "failed" want not match against , unfortunately need "regex"-solution ie re.search(regex, string) since not have access code outside of input variables regex , string.

if directly in python have avoided regex start with. ;)

if understand correctly, want make sure string 'failed' not appear anywhere before string 'stopword'. assuming that's case, it's easiest failed appearing before stopword , invert result. assuming text input:

not re.match(r'.*?failed.*?stopword', text, re.dotall) 

of course, easier straight python:

'failed' not in text.split('stopword')[0] 

Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -