# LPeg - A pattern-matching library

**URL:** <https://forum.defold.com/t/lpeg-a-pattern-matching-library/65654>\
**Category:** The Defoldmine\
**Created:** [June 24, 2020, 10:16am UTC](https://forum.defold.com/t/lpeg-a-pattern-matching-library/65654 "2020-06-24T10:16:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![astrochili](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/astrochili/32/37266_2.png) [@astrochili](https://forum.defold.com/u/astrochili)\
**Post date:** [June 24, 2020, 10:16am UTC](https://forum.defold.com/t/lpeg-a-pattern-matching-library/65654/1 "2020-06-24T10:16:10Z")

</div>

![lpeg](https://forum-defold-uploads.b-cdn.net/original/3X/b/2/b2a5cf05b312c668550e05919f5fba81f1c1bdad.jpeg)

# LPeg for Defold

[LPeg](http://www.inf.puc-rio.br/~roberto/lpeg/) is a pattern-matching library by [Roberto Ierusalimschy](http://www.inf.puc-rio.br/~roberto/) for Lua.

This extension includes source code of LPeg 1.0.2 (MIT Licence).

## Installation

Add the link to the latest [release zip-archive](https://github.com/astrochili/defold-lpeg/releases) as a [library dependency](http://www.defold.com/manuals/libraries/) in the Defold project configuration.

```plaintext
https://github.com/astrochili/defold-lpeg/archive/master.zip

```

## Usage

All operations are accessible through the global variable `lpeg`.

```lua
local P = lpeg.P 

local pattern = P'a' * P'b' ^ 0
local result = lpeg.match(pattern, 'abbc')

print(result) --> 4

```

## Examples

This library is used by [Narrator](https://forum.defold.com/t/narrator-the-ink-narrative-scripting-language-runtime/65653) to parse the Ink language. You can check how its parser works [here](https://github.com/astrochili/narrator/blob/master/narrator/parser.lua).

Also you can check this [tutorial](http://lua-users.org/wiki/LpegTutorial).
