Sorry but that is a dreadful test harness that has too many bugs that are nothing directly to do with regex. Test harnesses should follow the KISS Principal ; yours most definitely does not. The String class is just clutter and I have never needed it when using C++ on an Arduino and certainly is not needed here.
Using the following test harness I match a semicolon without problems.
#include <Regexp.h>
void setup() {
Serial.begin(115200);
process_cmd("; Hello will match");
process_cmd("some rubbish at the front but should still find the key bits ; Hello will match");
process_cmd("; Hello some other rubbish that does not matter since it will still match");
process_cmd("; Helo should not match");
}
void process_cmd(char* str) {
char regex[] = " *; Hello"; // PATTERN PATTERN PATTERN
Serial.print("CMD:[");
Serial.print(str);
Serial.print("] ");
Serial.println(strlen(str));
MatchState ms;
ms.Target(str);
char r = ms.Match(regex, 0);
Serial.println( r == REGEXP_MATCHED ? "MATCH" : "NO MATCH") ;
}//process_cmd
void loop() {
}//loop
You need to spend time with the regex library documentation and with the examples. That would have saved you days of wasted time.
Edit: I have just spend some time playing with the Regex library and experienced results I don't expect. The anomalies center around the repetition operators when applied to a group. I can't say the results are definitely wrong but at this time I would not use the library. I shall spend a bit of time trying to understand the apparent anomalies.
Edit 2 : It seems that the repetition operator do not seem to be able to be applied to a group. To me this is a serious limitation. A test program is
#include <Regexp.h>
void setup() {
Serial.begin(115200);
// These next two regex demostrate that the {n,m} repetition operators applied to a grouping are not implemented. I can't
// find anything in the documentation that says it is so not a bug just a limitation.
process_cmd("(%x%x){2,}$", " 12ab3456{2,}"); // Matches - treats the {2,} as literal text and a repetition
process_cmd("(%x%x){2,}$", " 12ab3456{2,};"); // As expected this fails to match due to the semicolon at the end of the line
// This demostrates that '+' (1 or more) repetition operator applied to a group is not implemented
process_cmd("^%x+$", "12ab3456"); // I would expect this to match and it does
process_cmd("^(%x%x)+$", "12ab3456"); // I would expect this to match but it doesn't
}
void process_cmd(char* regex, char* str) {
Serial.print("CMD:[");
Serial.print(str);
Serial.print("] ");
Serial.println(strlen(str));
MatchState ms;
ms.Target(str);
char r = ms.Match(regex, 0);
Serial.println( r, HEX ) ;
Serial.println( r == REGEXP_MATCHED ? "MATCH" : "NO MATCH") ;
}//process_cmd
void loop() {
}//loop