Giter VIP home page Giter VIP logo

go-pcre's Introduction

go-pcre

GoDoc

This is a Go language package providing support for Perl Compatible Regular Expressions (PCRE).

Installation

Install the package for Debian as follows:

sudo apt-get install libpcre++-dev
go get github.com/gijsbers/go-pcre

Usage

Go programs that depend on this package should import this package as follows to allow automatic downloading:

import "github.com/gijsbers/go-pcre"

History

This is a clone of golang-pkg-pcre by Florian Weimer, which has been placed on Github by Glenn Brown, so it can be fetched automatically by Go's package installer.

Glenn Brown added FindIndex() and ReplaceAll() to mimic functions in Go's default regexp package.

Mathieu Payeur Levallois added Matcher.ExtractString().

Malte Nuhn added GroupIndices() to retrieve positions of a matching group.

Chandra Sekar S added Index() and stopped invoking Match() twice in FindIndex().

Misakwa added support for pkg-config to locate libpcre.

Yann Ramin added ReplaceAllString() and changed Compile() return type to error.

Nikolay Sivko modified name2index() to return error instead of panic.

Harry Waye exposed raw pcre_exec.

Hazzadous added partial match support.

Pavel Gryaznov added support for JIT compilation.

go-pcre's People

Contributors

cskr avatar d4l3k avatar def avatar fweimer avatar gijsbers avatar glenn-brown avatar mathpl avatar mnuhn avatar theatrus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

go-pcre's Issues

CompileJIT is not threadsafe

pcrejit requires a separate thread specific stack. This leads to some very weird issues when using this library with multiple threads. I naively called CompileJIT in one part of the program and then used it in other parts without realizing that per thread stacks were required. This isn't featured in the documentation, nor is there a way to handle it in the current Go API.

http://www.pcre.org/original/doc/html/pcrejit.html#SEC9

http://www.pcre.org/original/doc/html/pcreapi.html#SEC8

https://stackoverflow.com/questions/28738674/is-the-pcre-library-thread-safe-if-not-which-do-you-recommend

package main

import (
	"log"

	pcre "github.com/gijsbers/go-pcre"
)

func findIndex(a pcre.Regexp) {
	for {
		// Compile a new function with JIT. Since this is running in a goroutine and
		// probably a different thread the JIT stack will be violated.
		b := pcre.MustCompileJIT("[^\\/><\\s]+", 0, 0)
		if b.FindIndex([]byte(" <p>"), 0) == nil {
			log.Fatal("b.FindIndex(...) should never equal nil")
		}

		if a.FindIndex([]byte(" <p>"), 0) == nil {
			log.Fatal("a.FindIndex(...) should never equal nil")
		}
	}
}

func main() {
	a := pcre.MustCompileJIT("[^\\/><\\s]+", 0, 0)
	for i := 0; i < 4; i++ {
		go findIndex(a)
	}
	findIndex(a)
}

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.