深圳专业网站设计哪家好,wordpress缺陷,如何删除网站的信息吗,怎么让织梦网站适合手机判断字符串是否包含正则表达式默认的特殊字符
业务描述#xff1a;
上层配置的字符列表中#xff0c;既有准确的字符串#xff0c;又有可以进行正则匹配的字符串#xff0c;这时候需要区分出来那些是正则匹配的字符串。
思路:
判断字符串中#xff0c;是否存在正则表达…判断字符串是否包含正则表达式默认的特殊字符
业务描述
上层配置的字符列表中既有准确的字符串又有可以进行正则匹配的字符串这时候需要区分出来那些是正则匹配的字符串。
思路:
判断字符串中是否存在正则表达式默认的特殊字符如*^${}等。
代码 #include iostream
#include regexusing namespace std;// check if code contains regex special chars:*$^?\{}|
static const string regexLimit {.*[*$^?\\\\{}|].*};
static const std::regex pattern(regexLimit);
bool isRegex(const std::string str) {try {return std::regex_match(str, pattern);}catch(const std::exception e) {std::cout regex error: e.what() endl;return false;}
}int main(int argc, char const *argv[])
{std::cout hello world! std::endl;string temp1 *demo.*;string temp2 ^com.*.demo.*;string temp3 car$;string temp4 com.ddmode;string temp5 com.d?dmode;string temp6 com.d\\dmode;string temp7 com.d{dmode;string temp8 com.d}dmode;string temp9 com.d|dmode;string temp41 com.demo.test;vectorstd::string list;list.push_back(temp1);list.push_back(temp2);list.push_back(temp3);list.push_back(temp4);list.push_back(temp5);list.push_back(temp6);list.push_back(temp7);list.push_back(temp8);list.push_back(temp9);list.push_back(temp41);for (size_t i 0; i list.size(); i){bool result isRegex(list[i]);printf(i:%ld isRegex?:%d\n, i, result);}printf(hello world end.);return 0;
}输出
hello world!
i:0 isRegex?:1
i:1 isRegex?:1
i:2 isRegex?:1
i:3 isRegex?:1
i:4 isRegex?:1
i:5 isRegex?:1
i:6 isRegex?:1
i:7 isRegex?:1
i:8 isRegex?:1
i:9 isRegex?:0
hello world end.