// URL that generated this code:
// http://txt2re.com/index-cpcre.php3?s=42%2043&2&-10&-6
#include <stdio.h>
#include <string.h>
#include <pcre.h>
int main(int argc, char **argv)
{
const char *error;
int erroffset;
int ovector[186];
char re[8192]="";
char txt[]="42 43";
char re1[]=".*?"; // Non-greedy match on filler
strcat(re,re1);
char re2[]="(2)"; // Any Single Digit 1
strcat(re,re2);
char re3[]="( )"; // Any Single Character 1
strcat(re,re3);
char re4[]="(\\d+)"; // Integer Number 1
strcat(re,re4);
pcre *r = pcre_compile(re, PCRE_CASELESS|PCRE_DOTALL, &error, &erroffset, NULL);
int rc = pcre_exec(r, NULL, txt, strlen(txt), 0, 0, ovector, 186);
if (rc>0)
{
char d1[1024];
pcre_copy_substring(txt, ovector, rc,1,d1, 1024);
printf("(%s)",d1);
char c1[1024];
pcre_copy_substring(txt, ovector, rc,2,c1, 1024);
printf("(%s)",c1);
char int1[1024];
pcre_copy_substring(txt, ovector, rc,3,int1, 1024);
printf("(%s)",int1);
puts("\n");
}
}
//-----
// C does not provide a regular expression feature as standard.
//
// To run this code you will need to first download and install
// the PCRE library from http://www.pcre.org/
//
// Note that on Linux systems PCRE is often already installed in /usr/lib/libpcre* or /usr/local/lib/libpcre*.
//
// Compile and on Unix using:
// # gcc -lpcre x.c
// # ./a.out
//
 
Feedback
KisnardOnline::
perfect perfect perfect... get some ads on this site, so we can thank you more
Wed, 29 May 2013 10:21PM
ShubhamGupta::
Saved my day!
Wed, 29 May 2013 11:36PM
::
Thu, 30 May 2013 12:02AM
Astarte::
Awesome, just awesome!
Thu, 30 May 2013 12:03AM
David Dawkins::
Excellent tool, where's the donate link? thank-you !!!