LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
RegexMatch.cc
Go to the documentation of this file.
1 // functions used to assist with regular expression matching of strings
2 
4 #include "cetlib/replace_all.h"
5 
6 #include <regex>
7 #include <string>
8 #include <vector>
9 
10 namespace art {
11 
12  bool
13  is_glob(std::string const& pattern)
14  {
15  return (pattern.find_first_of("*?") != std::string::npos);
16  }
17 
18  std::string
19  glob2reg(std::string pattern)
20  {
21  cet::replace_all(pattern, "*", ".*");
22  cet::replace_all(pattern, "?", ".");
23  return pattern;
24  }
25 
27  regexMatch(std::vector<std::string> const& strings, std::regex const& regexp)
28  {
30  for (auto i = strings.begin(), iEnd = strings.end(); i != iEnd; ++i) {
31  if (std::regex_match((*i), regexp)) {
32  matches.push_back(i);
33  }
34  }
35  return matches;
36  }
37 
39  regexMatch(std::vector<std::string> const& strings,
40  std::string const& pattern)
41  {
42  std::regex const regexp{glob2reg(pattern)};
43  return regexMatch(strings, regexp);
44  }
45 }
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, std::regex const &regexp)
Definition: RegexMatch.cc:27
intermediate_table::const_iterator const_iterator
std::string glob2reg(std::string pattern)
Definition: RegexMatch.cc:19
HLT enums.
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:13