From Corrupt Pintail, 4 Years ago, written in C.
This paste is a reply to Untitled from Queen Dove
- view diff
Embed
  1. #define _GNU_SOURCE
  2.  
  3. #include <regex.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. // http://stackoverflow.com/questions/2359811/working-with-gnu-regex-functions-in-c-or-c
  8.  
  9. int main() {
  10.    int i;
  11.    char pat_str[] = "\\(.*\\)\\(FS#[0-9]+\\)\\(.*\\)";
  12.    //char pat_str[] = ".*FS#[0-9]+.*";
  13.    struct re_pattern_buffer pat_buff;
  14.    struct re_registers regs;
  15.    pat_buff.translate = 0;
  16.    pat_buff.fastmap = 0;
  17.    pat_buff.buffer = 0;
  18.    pat_buff.allocated = 0;
  19.    //pat_buff.syntax = _RE_SYNTAX_POSIX_COMMON;
  20.    re_syntax_options = _RE_SYNTAX_POSIX_COMMON;
  21.  
  22.    re_compile_pattern(pat_str, sizeof(pat_str) - 1, &pat_buff);
  23.    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"};
  24.  
  25.    for (i = 0; i < sizeof(strings)/sizeof(char*); i++) {
  26.       int match_ret = re_match(&pat_buff, strings[i], strlen(strings[i]), 0, &regs);
  27.       if (match_ret >= 0) {
  28.          printf("juhu %d\n", regs.num_regs);
  29.          int j;
  30.          // first is all, last is -1,-1
  31.          for (j = 1; j < regs.num_regs - 1; j++) {
  32.             int s = regs.start[j];
  33.             int e = regs.end[j];
  34.             printf("%d: %d -> %d \"%.*s\"\n", j, s, e, e - s, strings[i] + s);
  35.          }
  36.       } else if (match_ret == -1) {
  37.          printf("ohno\n");
  38.       } else {
  39.          printf("error\n");
  40.       }
  41.    }
  42.  
  43.    regfree(&pat_buff);
  44. }
  45.  

Replies to Re: Untitled rss

Title Name Language When
Re: Re: Untitled Scribby Shama c 4 Years ago.