RegexMatch.cxx
Go to the documentation of this file.
2 #include <cstdlib>
3 //extern "C" {
4 #include <regex.h>
5 //}
6 
8 {
9  // Change the wild card pattern into a regex
10  std::string p = "^";
11  for (unsigned int i=0; i<w.size(); ++i) {
12  if (w[i]=='*') p += ".*";
13  else if (w[i]=='.') p += "\\.";
14  else p += w[i];
15  }
16  p += '$';
17 
18  //
19  // Compose the regular expression structure from the pattern string
20  //
21  regex_t re;
22  int ierr = regcomp(&re, p.c_str(), REG_EXTENDED|REG_NOSUB);
23  if (ierr!=0) abort();
24 
25  //
26  // Test s against the pattern. 0 = match, 1 = no match
27  //
28  int stat = regexec(&re, s.c_str(), 0, 0, 0);
29 
30  regfree(&re);
31 
32  return stat;
33 }
34 ////////////////////////////////////////////////////////////////////////
35 
const char * p
Definition: xmltok.h:285
const XML_Char * s
Definition: expat.h:262
int regex_match(const std::string &s, const std::string &p)
Definition: RegexMatch.cxx:7
Float_t w
Definition: plot.C:20
enum BeamMode string