Regex usage in TSystem::ListLibraries()

//
// Usage example:
// root -l -q 'ListLibraries.cxx(".*libCore\\..*")'
//
#include "TString.h"
#include "TRegexp.h"
#include "TSystem.h"
#include <iostream>
void ListLibraries(const char *regexp = ".*", Bool_t wildcard = kFALSE) {
  if (!gSystem) return; // just a precaution
  if (!(regexp && regexp[0])) regexp = (wildcard ? "*" : ".*");
  TRegexp pat(regexp, wildcard);
  TString libs(gSystem->GetLibraries());
  TString tok;
  Ssiz_t from = 0, ext;
  while (libs.Tokenize(tok, from, " ")) {
    if ((tok.Index(pat, &ext) != 0) || (ext != tok.Length())) continue;
    std::cout << tok << "\n";
  }
}