LoginSignup
2
1

More than 5 years have passed since last update.

arduinoでregex

Last updated at Posted at 2017-11-16

概要

arduinoで正規表現やってみた。
regex.hが見つからないので、slre.hやってみた。

写真

image

サンプルコード

#include "slre.h"

void setup()
{
    Serial.begin(115200);
    while (!Serial) delay(250);
    Serial.print("ok");
    Serial.println();
    const char * request = " GET /index.html HTTP/1.0\r\n\r\n";
    struct slre_cap caps[4];
    char t[64];
    if (slre_match("^\\s*(\\S+)\\s+(\\S+)\\s+HTTP/(\\d)\\.(\\d)", request, strlen(request), caps, 4, 0) > 0)
    {
        //Serial.println(caps[0].len);
        //Serial.println(caps[0].ptr);
        //Serial.println(caps[1].len);
        //Serial.println(caps[1].ptr);
        //Serial.println(caps[2].len);
        //Serial.println(caps[2].ptr);
        strncpy(t, caps[0].ptr, caps[0].len);
        t[caps[0].len] = '\0';
        Serial.print("method : ");
        Serial.println(t);
        strncpy(t, caps[1].ptr, caps[1].len);
        t[caps[1].len] = '\0';
        Serial.print("url : ");
        Serial.println(t);
        strncpy(t, caps[2].ptr, caps[2].len);
        t[caps[2].len] = '\0';
        Serial.print("http : ");
        Serial.println(t);
    }
    else
    {
        Serial.print("Error parsing: ");
        Serial.println(request);
    }
}
void loop()
{
}

ライブラリ

以上。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1