#define _GNU_SOURCE #include <regex.h> #include <stdio.h> #include <string.h> // http://stackoverflow.com/questions/2359811/working-with-gnu-regex-functions-in-c-or-c int main() { int i; char pat_str[] = "\\(.*\\)\\(FS#[0-9]+\\)\\(.*\\)"; //char pat_str[] = ".*FS#[0-9]+.*"; struct re_pattern_buffer pat_buff; struct re_registers regs; pat_buff.translate = 0; pat_buff.fastmap = 0; pat_buff.buffer = 0; pat_buff.allocated = 0; //pat_buff.syntax = _RE_SYNTAX_POSIX_COMMON; re_syntax_options = _RE_SYNTAX_POSIX_COMMON; re_compile_pattern(pat_str, sizeof(pat_str) - 1, &pat_buff); char* strings[] = {"Partially implements FS#6: Conference ID changed to c+bugs@conference.thedevstack.de", "abc\nblubb FS#123 abc", "FS#123 abcdef", "abcdef FS#123", "blubber"}; for (i = 0; i < sizeof(strings)/sizeof(char*); i++) { if (match_ret >= 0) { int j; // first is all, last is -1,-1 for (j = 1; j < regs.num_regs - 1; j++) { int s = regs.start[j]; int e = regs.end[j]; } } else if (match_ret == -1) { } else { } } regfree(&pat_buff); }
Title | Name | Language | UNIX | When |
---|---|---|---|---|
Re: Re: Untitled | Scribby Shama | c | 1456407905 | 7 Years ago. |