Having problem with regex when target contains quotes

Arduino IDE 2.0.0-rc7
Device: Mega2560

The regex expression works on several online regex testers.
But on Arduino I get No match. I just want to get some capture groups.
Looking for advice or insight into what I'm doing wrong.

Output from program code shown here:

debug: buf = : { "english":"27", "token":"50", "hex":"100" }
No match.
ret=cmd:r

#include <Arduino.h>
#include <Regexp.h>

void setup ()
{
  Serial.begin (9600);
  Serial.println ();
  
  MatchState ms;
  char buf [100];  
  strcpy(buf,"{ \"english\":\"27\", \"token\":\"50\", \"hex\":\"100\" }");
  Serial.println(buf);

  ms.Target(buf);
  char result = ms.Match ("(\".*?\"):(\".*?\")", 0);
  // check results
  switch (result)
  {
    case REGEXP_MATCHED:
      
      Serial.println ("-----");
      Serial.print ("Matched on: ");
      Serial.println (ms.GetMatch (buf));
      
      // matching offsets in ms.capture
      
      Serial.print ("Captures: ");
      Serial.println (ms.level);
      
      for (int j = 0; j < ms.level; j++)
      {
        Serial.print ("Capture number: ");
        Serial.println (j + 1, DEC);
        Serial.print ("Text: '");
        Serial.print (ms.GetCapture (buf, j));
        Serial.println ("'");
        
      }
      break;  
      
    case REGEXP_NOMATCH:
      Serial.println ("No match.");
      break;
      
    default:
      Serial.print ("Regexp error: ");
      Serial.println (result, DEC);
      break;
  }  // end of switch
  
}  // end of setup

void loop () {}

The regex is a bit different for greedy v. non-greedy

char result = ms.Match ("(".-"):(".-")", 0);

from MUSHclient documentation: contents

Repetition

The repetition characters, which can follow a character, class or set, are:


+  ---> 1 or more repetitions (greedy)
*  ---> 0 or more repetitions (greedy)
-  ---> 0 or more repetitions (non greedy)
?  ---> 0 or 1 repetition only

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.