简体   繁体   English

正则表达式,表示“不在值列表中”,且不带负前瞻

[英]Regular expression for “not in a list of values” without negative lookahead

I want to search for a string that doesn't exist in a list of strings by using regex. 我想使用正则表达式搜索字符串列表中不存在的字符串。 Is it possible to make a regex for that case without using negative lookahead ? 是否可以在使用负前瞻的情况针对这种情况制作正则表达式?

只需将正则表达式用于“在值列表中”,如果匹配则返回False

When you just search for a plain string in a list of strings you don't even need regex. 当您仅在字符串列表中搜索纯字符串时,您甚至不需要正则表达式。 you can just do string not in list_of_strings 你可以只string not in list_of_stringsstring not in list_of_strings

For example if you have 例如,如果您有

list_of_string = ['string1', 'string2', 'string3']
string = 'string4'

string not in list_of_strings would result in True string not in list_of_strings将导致True

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM