#include // "Regular expression matching" // You can search for, and install the regex library from the Arduino library manager. // See http://www.gammon.com.au/forum/?id=11063 for documentation on using the regex arduino library void setup () { Serial.begin (9600); Serial.println (); // what we are searching (the target) char target[100] = "A quick brown fox x: 126 jumps over y: 621 some lazy wolf"; char captured[100]; // A string variable for the regex "captured" results // match state object, also initializes ms MatchState ms; // specify the string to be analyzed for matches ms.Target(target); // print the target to be analyzed Serial.println (target); //Search for a pattern using these regular expression codes: // %s = any number of spaces // %d+ = any number of digits (at least 1) // (%d+) = CAPTURE those digits and make them available to your sketch // search for: [spaces] x: [spaces] ([a bunch of digits]) [spaces] char result = ms.Match ("%sx:%s(%d+)%s"); // Was there a match?? if (result == REGEXP_MATCHED) { // This would give you the total number of captures, // But if you're only expecting 1, it's enough to check that result == REGEXP_MATCHED //int count=ms.level; //Serial.println (count); // Get the first (number 0) captured expression and put in the string variable called 'captured' ms.GetCapture(captured, 0); Serial.print("x="); Serial.println(captured); // But "captured" is a string variable. You probably want an integer variable instead. // "atoi" stands for "alphanumeric to integer" int x = atoi(captured); Serial.print("x = "); Serial.println(x); if (x==126){ Serial.println("Sho' nuff, x is 126"); } } //Now much quicker, let's pull out y from the same target string: int y= 0; result = ms.Match ("%sy:%s(%d+)%s"); if (result == REGEXP_MATCHED){ ms.GetCapture(captured, 0); y = atoi(captured); Serial.print("y = "); Serial.println(y); } } // end of setup void loop () {}