LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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
11  is_glob(std::string const& pattern)
12  {
13  return pattern.find_first_of("*?") != std::string::npos;
14  }
15 
16  std::string
17  glob2reg(std::string pattern)
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
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
std::string glob2reg(std::string pattern)
Definition: RegexMatch.cc:17
Definition: MVAAlg.h:12
Float_t e
Definition: plot.C:35
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:11