我需要regex才能找到this String
以外的任何内容
示例数据是:
this is one line with this string only this should not match
this is another line but has no string in
this String is another
and then this line should match also
我想找到并突出整行,所以行
this is one line with this string
是唯一将被选中的人。
我尝试^(?!(this String)$)
,但这找不到长度匹配,所以帮助不大,我尝试在各个地方添加.*
,但不明白该怎么做。
答案 0 :(得分:0)
您可能根本不需要正则表达式完成此任务。看看这两段代码:
std::regex pattern("^((?!this string).)*$");
while (std::getline(infile, chkme)) {
if (std::regex_match(chkme,pattern)) {
std::cout << "Not found! " << chkme;
}}
和
std::string pattern = "this string";
while (std::getline(infile, chkme)) {
if (chkme.find(pattern) == string::npos) {
std::cout << "Not found! " << chkme;
}}