RegexMatch.cc
Go to the documentation of this file.
2 #include "cetlib/replace_all.h"
3 
4 #include <regex>
5 #include <string>
6 #include <vector>
7 
8 namespace art {
9 
10  bool
12  {
13  return pattern.find_first_of("*?") != std::string::npos;
14  }
15 
18  {
19  cet::replace_all(pattern, "*", ".*");
20  cet::replace_all(pattern, "?", ".");
21  return pattern;
22  }
23 
25  regexMatch(std::vector<std::string> const& strings,
26  std::string const& pattern)
27  {
28  auto const reg_str = glob2reg(pattern);
29  // We allow for a trigger-bit to lead the trigger path name.
30  std::regex const regexp{"(\\d+:)?" + glob2reg(pattern)};
32  for (auto it = strings.begin(), e = strings.end(); it != e; ++it) {
33  if (std::regex_match(*it, regexp)) {
34  result.push_back(it);
35  }
36  }
37  return result;
38  }
39 
40 } // namespace art
static QCString result
std::string string
Definition: nybbler.cc:12
intermediate_table::const_iterator const_iterator
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, std::string const &pattern)
Definition: RegexMatch.cc:25
bool replace_all(std::string &in, std::string const &from, std::string const &to)
Replace all occurrences of from in string with to.
Definition: replace_all.cc:4
const double e
std::string glob2reg(std::string pattern)
Definition: RegexMatch.cc:17
std::string pattern
Definition: regex_t.cc:35
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:11