Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <regex.h>
- #include <stdio.h>
- static int match(const char *string, const char *regex) {
- regex_t preg;
- regcomp(&preg, regex, REG_EXTENDED);
- if (!regexec(&preg, string, 0, NULL, 0)) return 1;
- return 0;
- }
- int main(void) {
- int i;
- const char * const greeting[] = {
- "○○さん、こんにちは",
- "こんにちわ、○○さん",
- "○○さん、こんばんは",
- "こんばんわ、○○さん"
- };
- const char hello[] = "こんにち(わ|は)";
- for (i = 0; i < sizeof(greeting) / sizeof(char **); i++) {
- if (match(greeting[i], hello))
- printf("%s\nこんにちは\n", greeting[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement