stowite;
Here is a simple sketch to test re(s) by compiling the pattern and reading in the target from the Serial port.
I have not been able to match something as simple as a colon followed by an arbitrary character from the keyboard (except with a pattern like ":." which accepts pretty much anything.
What I'd like to do is match a colon followed by EITHER, exactly 1 letter or number character OR exactly 2 hex digits.
These would match ":1" OR ":af" -- anything else would NOT MATCH.
#define pr(x) Serial.print(#x"=");Serial.println(x);
#include <Regexp.h>
String in_str = "";
boolean CMD_RECVD = false;
MatchState ms;
void setup() {
Serial.begin(9600);
Serial.println("WAITing for Command on Serial Port:");
}
void loop() {
if (CMD_RECVD) {
process_cmd(in_str); //complete command including \n
in_str = "";
CMD_RECVD = false;
Serial.println("...\nWAITing for Command on Serial Port:");
}
}//loop
void process_cmd(String str) {
boolean r = false; char s[100];
char pattern[] = ":.{1,2}"; // PATTERN PATTERN PATTERN
//str.replace("\n","\0");
Serial.print("CMD RECEIVED:[");Serial.print(str);
Serial.print("] "); pr(str.length());
str.getBytes(s, str.length()+1);
ms.Target(s);
r = ms.Match(pattern, 0);
(r) ? Serial.println("MATCH") : Serial.println("NO MATCH");
}//process_cmd
void serialEvent() {
while (Serial.available()) { // Chk if anything is there
char inChar = (char)Serial.read(); // Get nxt byte
if (inChar != '\n')
in_str += inChar; // skip \n
else
CMD_RECVD = true; // signals END
}//while
}//serialEvent