Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2006-04-25 13:38:03


> I would like to implement matching of SQL-LIKE clauses by Boost regex.
> I need to convert strings like "HEL_LO%" into something
> regex("HEL.LO.*"). As the LIKE-string might contain characters like
> '.', '+* etc these need to be escaped: "HE+LO%" -> regex("HE\+LO.*").
>
> Another example are shell globs where * and ? take the place of % and
> _.
>

One way is to write a regex to change your input syntax to a perl regex:

std::string dos_wildcard_to_regex(std::string s)
{
  static const boost::regex e("([.\\[{()\\+|^$])|(?)|(*)");
  return regex_replace(s, e, "(?1\\$1)(?2.)(?3.*)", match_default |
format_all);
}

Which relies on the "conditional search and replace" built into Boost.Regex.

HTH, John.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net