My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members

SLRE is an ANSI C library that implements a tiny subset of Perl regular expressions. It is primarily targeted for developers who want to parse configuation files, where speed is unimportant. It is in single .c file, easily modifiable for custom needs. For example, if one wants to introduce a new metacharacter, '\i', that means 'IP address', it is easy to do so.

The API is documented in http://code.google.com/p/slre/source/browse/slre.h.

Example of parsing HTTP request:

  const char *error_string;
  char method[10], uri[512];
  int http_version_minor, http_version_major;

  error_string = slre_match(
    "^(GET|POST) (\\S+) HTTP/(\\d)\.(\\d)",
    "GET /index.html HTTP/1.0",
     SLRE_STRING, method, sizeof(method),
     SLRE_STRING, uri, sizeof(uri),
     SLRE_INT, &http_version_major, sizeof(http_version_major),
     SLRE_INT, &http_version_minor, sizeof(http_version_minor));

  if (error_string == NULL) {
    printf("URI: [%s]\n", uri);
  } else {
    printf("Parse error: [%s]\n", error_string);
  }

Powered by Google Project Hosting