e2r3p13 / libregex

A lightweight C regex library. Educational project, use it at your own risk.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

libregex - A lightweight regular expressions C library

Overview

Regular expressions are very useful to describe a formal language. We made a small library that converts a given regular expression into a language (represented by a DFA). Then, several functions helps you to find occurrences of a valid sentence for this language.

Public API

int    re_compile(t_regex *regex, const char *str);
size_t re_execute(t_regex *regex, const char *str, size_t nmatch, t_rematch *pmatch);
int    re_nextmatch(t_regex *regex, const char *str, char **saveptr, t_rematch *match);
int    re_fullmatch(t_regex *regex, const char *str);
size_t re_count(t_regex *regex, const char *str);
void   re_free(t_regex *regex);

Installation

# Download & compile the project
git clone https://github.com/lfalkau/libregex
cd libregex
make

# Optionally install it
make install

Supported regex operators

Character classes Special characters Escape sequences Groups and ranges Quantifiers
\c Control character \n New line \ Escape following character . Any character except newline (\n) * 0 or more
\s Whitespace \r Carriage return (a❘b) a or b + 1 or more
\S Not whitespace \t Tab (...) Group ? 0 or 1 (optional)
\d Digit \v Vertical tab [abc] Single character (a or b or c)
\D Not digit \f Form feed [^abc] Single character (not a or b or c)
\w Word [a-q] Single character range (a or b ... or q)
\W Not word [A-Z] Single character range (A or B ... or Z)
\x Hexadecimal digit [0-9] Single digit from 0 to 9
\O Octal digit

Ressources

About

A lightweight C regex library. Educational project, use it at your own risk.


Languages

Language:C 94.8%Language:Makefile 5.2%