Coder Social home page Coder Social logo

lua-re2's Introduction

C and Lua wrappers for RE2

C and Lua wrapper for RE2 regular expression library. The Lua wrapper is built on top of C wrapper.

Lua Functions

The Lua wrapper (lua-re2.lua) exposes following functions:

new

syntax: instance = new()

Create an instance which pre-allocate some data structures for captures, to obviate the need of allocating them each time match is called.

The default value of the parameter max-capture is 40.

compile

syntax: pattern, capture_num, err_msg = compile(pattern, [options, max_mem])

Pre-compile the pattern string. Additional options for the regex engine can be passed by the options and max_mem; they are corresponding to RE2's re2::RE2::Options except that the options is using single character, instead of bitmask, to pass the boolean options. The respondance between options and RE2's re2::RE2::Options are following:

option char re2::RE2::Options meaning default value
u utf8 text and pattern are UTF-8; otherwise Latin-1 true
a longest_match search for longest match, not first match false
e log_errors log syntax and execution errors to ERROR true
l literal interpret string as literal, not regexp false
n never_nl never match \n, even if it is in regexp false
s dot_nl dot matches everything including new line false
c never_capture parse all parens as non-capturing false
i case_sensitive match is case-sensitive (regexp can override with (?i) unless in posix_syntax mode) true
m multi-line-mode ^ match after any newline, and $ match any before newline false

match

syntax: captures, errmsg = match(instance, pattern, text, cap_idx)

Match the given pre-compiled pattern against the text. It returns three variables:

| captures | the specified capture(s), see bellow | | errmsg | error message if something wrong took place |

The input parameter cap_idx can take one of the following values: | -1 | return all captures in an array, i-th (i>=0) element contains i-th capture, and 0-th element is the sub-string which tighly matches the entire pattern| | 1 .. the-number-of-capture | return particular capture |

find

syntax: match_or_not = find(pattern, text) return non-nil if match, nil otherwise

match_r

syntax: captures = match_r(instance, pattern, text)

Match the given pre-compiled pattern repeatedly through the full text. It returns all captures in an array if match, nil otherwise.

C Funtions

The interface functions are self-descriptive. Please check the re2c_c.h for details.

lua-re2's People

Contributors

yangshuxin avatar iaadoa avatar

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.