问题:
判断字符aa,ab,cd
匹配的字符串:aa|ad|cd|ab|af|cc|cd
要求: 通过正则,判断字符的组合 在 匹配的字符串 中存在
多个任意组合字符串匹配
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
超级小狗 2024-01-09 13:09关注#include <iostream> #include <regex> #include <string> int main() { // 定义要匹配的正则表达式模式 std::string pattern = "(?=.*aa)(?=.*ab)(?=.*cd)"; // 定义要进行匹配的字符串 std::string input = "aa|ad|cd|ab|af|cc|cd"; // 创建正则表达式对象 std::regex regex(pattern); // 使用 std::regex_search() 函数进行匹配 if (std::regex_search(input, regex)) { std::cout << "匹配成功" << std::endl; } else { std::cout << "匹配失败" << std::endl; } return 0; }解决 无用评论 打赏 举报