summaryrefslogtreecommitdiffstats
path: root/regexp.c
blob: c1706fb1e16dee5d67cfc98f4783a48960dfaeb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>

int main(int argc, char **argv)
{
    char *line = "  <img   src = \"bro.png\"  > ";
    char url[256] = { 0 };
    //sscanf(line, "<a href=\"%[^\"]\">", url);
    /* note: i love putting space in sscanf string, it treats them as one or more spaces */
    if (sscanf(line, " <%*[(a|img)] %*[(href|src)] = \"%[^\"]\">", url))
        puts(url);

    char name[50 + 1], email[50 + 1];
    char *string = "\"Bro Brotato\" <bro@hax.org>";

    /* i'm telling sscanf how string looks, %[] is the regexp */
    sscanf(string, "\"%50[^\"<]\" <%50[^>]", name, email);

    printf("name: \"%s\"\n", name);
    printf("email: \"%s\"\n", email);
}