Skip to content

Instantly share code, notes, and snippets.

@tyilo
Last active September 29, 2017 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyilo/d670cb304e72b7daed087ef9b492de03 to your computer and use it in GitHub Desktop.
Save tyilo/d670cb304e72b7daed087ef9b492de03 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#include <regex.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto & a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main() {
cin.sync_with_stdio(0); cin.tie(0);
cin.exceptions(cin.failbit);
string P;
getline(cin, P);
string re;
trav(c, P) {
if (c == '*') {
re += ".*";
} else if (c == '.') {
re += "\\.";
} else {
re += c;
}
}
re += '$';
regex_t buf{};
buf.fastmap = (char *)malloc(256);
if (re_compile_pattern(re.data(), sz(re), &buf)) {
return 1;
}
int n;
cin >> n;
string dummy;
getline(cin, dummy);
rep(i, 0, n) {
string S;
getline(cin, S);
int res = re_match(&buf, S.data(), sz(S), 0, nullptr);
if (res >= 0) {
cout << S << "\n";
}
}
regfree(&buf);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment