Simple Regex in C
Some breathtakingly beautiful programming from an early implementation of Regex
int matchhere(char *, char *);
int matchstar(int c, char *re, char *text) {
do {
if (matchhere(re, text)) return 1;
} while (*text && (*text++ == c || c == '.'));
return 0;
}
int matchhere(char *re, char *text) {
if (re[0] == '\0') return 1;
if (re[1] == '*')
return matchstar(re[0], re + 2, text);
if (re[0] == '$' && re[1] == '\0')
return *text == '\0';
if (*text && (re[0] == '.' || re[0] == *text))
return matchhere(re + 1, text + 1);
return 0;
}
int match(char *re, char *text) {
if (re[0] == '^')
return matchhere(re + 1, text);
for (;;) {
if (matchhere(re, text)) return 1;
if (*text++ == '\0') return 0;
}
}
Automated Archives for October, 29th 2026
This post was automatically generated.
Chess For the Day
Record: 5-1-2
Net Elo Change: +24
Games Played
- luchoaler - WIN
- Panda50 - LOSS
- ArrKyEnzo - WIN
- KRC_Game_2020 - LOSS
- Linkmaestro - WIN
- P_Zolnouri - WIN
- yevgen74 - WIN
- Yapana_Rayata - DRAW
Blog Posts On This Day
- October 29, 2025 (1 post)
- October 29, 2024 (3 posts)
- October 29, 2023 (1 post)
