Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- regex
- /******************************************************************************
- Online C Compiler.
- Code, Compile, Run and Debug C program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <stdio.h>
- #include <regex.h>
- regex_t regex;
- int reti;
- char msgbuf[100];
- int main()
- {
- /* Compile regular expression */
- reti = regcomp(®ex, "^duuii", 0);
- if (reti) {
- fprintf(stderr, "Could not compile regex\n");
- exit(1);
- }
- /* Execute regular expression */
- reti = regexec(®ex, "dupa8", 0, NULL, 0);
- if (!reti) {
- puts("Match");
- }
- else if (reti == REG_NOMATCH) {
- puts("No match");
- }
- else {
- regerror(reti, ®ex, msgbuf, sizeof(msgbuf));
- fprintf(stderr, "Regex match failed: %s\n", msgbuf);
- exit(1);
- }
- /* Free memory allocated to the pattern buffer by regcomp() */
- regfree(®ex);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement