I'm trying to split this string:
Code:
"SPEAKER: Hello there, my friend. SPEAKER2: How are you, friend?"
into an array.
I know to use the strtok function from the strings header file, but I'm running into an issue with the output.
Here is some test code:
Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv)
{
char* re = "[A-Z]+:(.)";
char text[400] = "SPEAKER: Hello there, my friend. SPEAKER2: How are you, friend?";
char* token = strtok(text, re);
while (token != NULL) {
printf("%s\n", token);
token = strtok(NULL, re);
}
return 0;
}
This is the result:
Code:
SPE
KER
Hello there, my friend
SPE
KER2
How are you, friend?
The code seems to split on 'A,' and I can't figure out if my regex is incorrect or something like this isn't possible in ANSI C. I've ran the regex through multiple debuggers, and they say its valid.
The ideal result would be:
Code:
SPEAKER
Hello there, my friend
SPEAKER2
How are you, friend?