Skip to content

Instantly share code, notes, and snippets.

@yukioc
Created February 13, 2012 15:46
Show Gist options
  • Save yukioc/1817728 to your computer and use it in GitHub Desktop.
Save yukioc/1817728 to your computer and use it in GitHub Desktop.
regex example using pcre.
#!/usr/bin/tcc -run -lpcre
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pcre.h>
int main(int argc,char*argv[]){
int ov[9],errofs;
char b[1024];
const char* err;
pcre *re=pcre_compile("Revision: (\\d+)",0,&err,&errofs,NULL);
while(fgets(b,1024,stdin)!='\0'){
if(pcre_exec(re,NULL,b,strlen(b),0,0,ov,9)>0){;
printf("%d",atoi(&b[ov[2]]));
}
}
free(re);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment