It is silly to use the totally unnecessary String, which creates additional problems with low-memory Arduinos.
Example:
char input_string[50] = "Hel lo,Wor ld!";
char * token;
char strings[4][10] = {0}; //up to four strings to receive the parsed data (each 9 characters max)
void setup()
{
Serial.begin(9600);
Serial.println();
byte index = 0; // index to index the strings array
token = strtok(input_string, " ,"); // get the first part
while (token != NULL )
{
strcpy(strings[index], token); //safer: use strncpy() instead
Serial.println( strings[index] ); //print each substring
index++; // increment the array position
token = strtok(NULL, " ,"); // get the next part
}
}
void loop()
{
}
The description of library is on cppreference. If you are not familiar with regular expressions, the part in the code above const std::regex ws_re(":| +"); means that there should be either ':' symbol or (or in regular expressions denoted by pipe symbol '|') any amount of whitespaces ('+' stands for 'one or more symbol that stands before the plus sign'). Then one is able to use this regular expression to tokenize any input with std::sregex_token_iterator. For more complex cases than whitespaces, there is wonderful regex101.
The only disadvantage I could think of is that regex engine is likely to be slower than simple handwritten tokenizer.