I am using the following code modified from the examples. I get the count of matches but the actual value is not displayed

#include <Regexp.h>

void setup() {
    MatchState ms;
    char buf [100];
    char buf2 [100] = "The quick brown fox jumps over the lazy wolf";
    ms.Target (buf2);
    unsigned int count = ms.MatchCount ("[aeiou]");

    Serial.print ("Found ");
    Serial.print (count);
    Serial.println (" matches.");
    for (int j = 0; j < count; j++)
          Serial.print ("Capture number: ");
          Serial.println (j, DEC);
          Serial.print ("Text: '");
          Serial.print (ms.GetCapture (buf, j));
          Serial.println ("'");
void loop(){}
  • Could you add the output you are getting, to your question?
    – Gerben
    Dec 31 '15 at 9:50

You haven't defined any capture groups in your regexp.

The regexp [aeiou] will match any of those characters, but it won't capture them. To capture you need to define a capture group which is a sequence of tokens surrounded by parenthesis. For instance:


In your test phrase "The quick brown fox jumps over the lazy wolf" that should match 11 times and capture each match, resulting in captures of e u i o o u o e e a o.

The reason why matching and capturing are two completely different things is so you can do things like [aeiou]([aeiou]) which would capture the second vowel in a two vowel sequence. In your example it would match the ui of quick and capture just the i.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.