mirror of https://github.com/cesanta/slre.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
9 years ago
|
---
|
||
|
title: "API"
|
||
|
---
|
||
|
|
||
|
```c
|
||
|
int slre_match(const char *regexp, const char *buf, int buf_len,
|
||
|
struct slre_cap *caps, int num_caps, int flags);
|
||
|
```
|
||
|
|
||
|
`slre_match()` matches string buffer `buf` of length `buf_len` against regular
|
||
|
expression `regexp`, which should conform the syntax outlined above. If regular
|
||
|
expression `regexp` contains brackets, `slre_match()` can capture the
|
||
|
respective substrings into the array of `struct slre_cap` structures:
|
||
|
|
||
|
```c
|
||
|
/* Stores matched fragment for the expression inside brackets */
|
||
|
struct slre_cap {
|
||
|
const char *ptr; /* Points to the matched fragment */
|
||
|
int len; /* Length of the matched fragment */
|
||
|
};
|
||
|
```
|
||
|
|
||
|
N-th member of the `caps` array will contain fragment that corresponds to the
|
||
|
N-th opening bracket in the `regex`, N is zero-based. `slre_match()` returns
|
||
|
number of bytes scanned from the beginning of the string. If return value is
|
||
|
greater or equal to 0, there is a match. If return value is less then 0, there
|
||
|
is no match. Negative return codes are as follows:
|
||
|
|
||
|
```c
|
||
|
#define SLRE_NO_MATCH -1
|
||
|
#define SLRE_UNEXPECTED_QUANTIFIER -2
|
||
|
#define SLRE_UNBALANCED_BRACKETS -3
|
||
|
#define SLRE_INTERNAL_ERROR -4
|
||
|
#define SLRE_INVALID_CHARACTER_SET -5
|
||
|
#define SLRE_INVALID_METACHARACTER -6
|
||
|
#define SLRE_CAPS_ARRAY_TOO_SMALL -7
|
||
|
#define SLRE_TOO_MANY_BRANCHES -8
|
||
|
#define SLRE_TOO_MANY_BRACKETS -9
|
||
|
```
|
||
|
|
||
|
Valid flags are:
|
||
|
|
||
|
- `SLRE_IGNORE_CASE`: do case-insensitive match
|