NeonBlack, the regex library can be compiled into exe too, correct? Thanks I got it!
C_ntua, I didn't know regex.re_nsub stores the number of maches, thanks!
So the problem I'm facing now is that my regex doesn't work as expected. I tested my regex on this website RegExr.
Pattern:
Code:
<title>(.*?)</title>
Text:
Code:
asd <title>title1</title> asdf <title>title2</title>as df <title>title3</title>sdf
The output - This is what I need!
asd
<title>title1</title> asdf
<title>title2</title>as df
<title>title3</title>sdf
However, this is what I'm getting with my code:
asd
<title>title1</title> asdf <title>title2</title>as df <title>title3</title>sdf
In the output below, the end shows the location of the last </title> instead of the first one. The re.re_nsub show only one match. It acts like I'm doing "<title>(.*)</title>", instead of "<title>(.*?)</title>" as a pattern. What am I doing wrong? Thank you!
Output:
Source:
Code:
#include <sys/types.h>
#include <regex.h>
#include <stdio.h>
int main(int argc, char *argv[]){
char buffer[] = "asd <title>title1</title> asdf <title>title2</title>as df <title>title3</title>sdf";
regex_t re;
regmatch_t pm;
int error;
(void) regcomp (&re, "<title>(.*?)</title>", REG_EXTENDED);
error = regexec (&re, &buffer[0], 1, &pm, 0);
printf("found: %i\n", re.re_nsub);
printf("str: %i\n", pm.rm_so);
printf("end: %i\n", pm.rm_eo);
return 0;
}