GitHub - tmikus/onig-go

1 min read Original article ↗

Oniguruma Go

Go bindings for the Oniguruma regex library, a powerful and mature regular expression library with support for a wide range of character sets and language syntaxes. Oniguruma is written in C.

Dual-licensed under MIT or the UNLICENSE.

Installation

Prerequisites:

In order to install onig-go, you need to have the Oniguruma library installed on your system.

You can install it using Homebrew:

Or on Ubuntu you can install it using apt:

sudo apt install libonig-dev libonig5

Installation:

To install onig-go, use the following command:

go get github.com/tmikus/onig-go

Example Usage

package main

import (
    "fmt"
    "github.com/tmikus/onig-go/v3"
)

func main() {
    regex, _ := onig.NewRegex("e(l+)")
    defer regex.Close()
    captures, _ := regex.Captures("hello")
    for text := range captures.All() {
        fmt.Println(text)
    }
}

For more examples, see the regex_test.go file.

Documentation

The API documentation is available at https://pkg.go.dev/github.com/tmikus/onig-go.