
Richard Dingwall
Cheers. I was rather hoping not to have to use regular expressions; they're kinda beyond the intended users of my program (it's for a user-defined filter function, and I don't expect them to be familiar with regex syntax).
I cheaped out and used an old C wildcmp(wild.c_str(), text.c_str()) method instead.
You can translate from wildcards syntax to regex one and then use string_algo that supports regex. For example: std::string wildcards_to_regex(std::string const& wildcard_pattern) { // replaces wildcards by corresponding regex expressions // mask all regex special characters (except wildcards characters "*?") std::string regex_pattern = boost::algorithm::replace_all_regex_copy(wildcard_pattern, boost::regex("[\\.\\[\\]\\{\\}\\(\\)\\\\\\+\\|\\^\\$]"), std::string("\\\\$&")); // replace wildcards by corresponding regex's boost::algorithm::replace_all_regex(regex_pattern, boost::regex("\\*"), std::string("\\.\\*")); boost::algorithm::replace_all_regex(regex_pattern, boost::regex("\\?"), std::string("\\.{1}")); return regex_pattern; } Test: assert(wildcards_to_regex("+[*?") == "\\+\\[.*.{1}"); To community and especially to Pavol Droba as the author of string_algo: What do you think about popularity of wildcards as the tool for end-users? Is it worth to add wildcards support to the library? To what library? Is the boost-development mailing list a better place for this discussion? Best regards, Andriy Tylychko, telia@vichnavich.com www.vichnavich.com