Coder Social home page Coder Social logo

regex's Introduction

regex

a pure C implementation of simple regular express engine, using DFA engine. the former is just for yes-or-no matching.

that's all begin from 正则表达式实现

Just for fun. ;)

pattern

pattern describe
$ matches the end of the string
ab matches a followed by b
matches a or b (ordered)
a* matches at least 0 repetitions of a
a? matches 0 or 1 repetitions of a
a+ matches 1 or more repetitions of a
(...) matches whatever regex is inside the parentheses, as a single element
[a-b] matches any characters between a and b (range)
. matches any characters, equivalent to the set [0-0xff]
\d matches any decimal digit, equivalent to the set [0-9]
\ escapes special characters

the following escaping sequences are supported:

escapes describe
\t tab
\n newline
\r return
\s space
\\ \
\( (
\) )
\[ [
\] ]
\- -
\. .
\+ +
\$ $

^ (matches the start of the string) is enabled by default.

todo list

  1. subset DFA
  2. backreference
  3. capture

api

// create/free a regex environment.
struct reg_env* reg_open_env();
void reg_close_env(struct reg_env* env);

// create/free a regex pattern.
struct reg_pattern* reg_new_pattern(struct reg_env* env, const char* rule);
void reg_free_pattern(struct reg_pattern* pattern);

// match pattern, return a boolean value.
int reg_match(struct reg_pattern* pattern, const char* source, int len);

see src/regex.h headfile for detail.

example

  // create env
  struct reg_env* env = reg_open_env();
  
  // create pattern
  struct reg_pattern* pattern = reg_new_pattern(env, rule);

  // match pattern
  int success = reg_match(pattern, source, strlen(source));

  // free env
  reg_close_env(env);

see test/test_api.c testcase for detail.

regex's People

Contributors

lvzixun avatar

Stargazers

quiz avatar Wenda Zhang avatar  Yangchao Zhou avatar  avatar  avatar 涵曦 avatar  avatar warjiang avatar ik5 avatar Eric Wong avatar perryn avatar w4v3 avatar 蔡相跃 avatar  avatar  avatar Pitter.liao avatar  avatar dydxh avatar Chao’s avatar  avatar Smurf avatar Jin avatar qianlihu avatar Muhammad Mominul Huque avatar wuxx avatar ruoxuanwang avatar xupingmao avatar Guangming Li  avatar Maciej avatar Vjkqxz avatar nibnat avatar Huaqi Fang avatar Xiaofan Hu avatar lujh avatar fisher_feng avatar Ihsoh avatar  avatar 左懶 avatar 小苏打 avatar Yecheng Fu avatar 梅梅 avatar  avatar HeisenBerg? avatar zjc avatar ruanxianhuo avatar Wuzeyi avatar  avatar  avatar Jayden.Lie avatar codedump avatar 阿楠 avatar xjdrew avatar

Watchers

 avatar tianchaijz avatar skyformat99 avatar  avatar

regex's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.