Coder Social home page Coder Social logo

golang-pkg-pcre's People

Contributors

fweimer avatar glenn-brown avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

golang-pkg-pcre's Issues

How to build using CGO_ENABLED=0 flag

How do we build a service using this library with CGO_ENABLED=0

Typically I build using this command:
CGO_ENABLED=0 GOOS=linux go build ./cmd/test_scripts

I got this error: go build github.com/myuser/myservice/vendor/github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre: build constraints exclude all Go files in /home/myuser/gocode/src/github.com/myuser/myservice/vendor/github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre

I tried this, but still get the same error
CGO_ENABLED=0 CGO_LDFLAGS="-lpcre" CGO_CFLAGS="-I/usr/lib/x86_64-linux-gnu" GOOS=linux go build -ldflags="-lpcre" -gcflags="-I/usr/lib/x86_64-linux-gnu" ./cmd/test_scripts

Does FindIndex call pcre_exec twice?

I have a question about FindIndex()(though I'm not sure if this project is still supported)... am I wrong, or does it call pcre_exec twice, first time via Matcher() - Reset() - Match() and then again via Match? I tried using the following replacement (Matchesinstead of Match), which seems to work, but I'm not sure if I miss something:

func (re *Regexp) FindIndex2(bytes []byte, flags int) []int {
	m := re.Matcher(bytes, flags)
	if m.Matches() {
		return []int{int(m.ovector[0]), int(m.ovector[1])}
	}
	return nil
}

However, I need the offset of all groups, not only the first one, plus additional information. Plus, I don't like changing other code, so I also tried this in my own code, which seems to work as well (but again, do I miss something?):

m := patt.Matcher(payload, 0)
if m.Matches() {
	grp := m.Group(0)
	off := len(payload) - cap(grp)

of curse this relies on the returned slice being part of the full subject array, which again is not perfect - but there is no official access to the offsets from outside the package.

Compile errors using go 1.7

Using go1.7.3 darwin/amd64 on CentOS7 and Mac, I am getting C compile errors when trying to use the pcre package. This did work beautifully before go 1.7. Perhaps a compiler switch is needed?

hostname:pcrematcher dfranke$ go build main.go

github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre

Undefined symbols for architecture x86_64:
"_pcre_compile", referenced from:
__cgo_73e035e15f71_Cfunc_pcre_compile in pcre.cgo2.o
(maybe you meant: __cgo_73e035e15f71_Cfunc_pcre_compile)
"_pcre_exec", referenced from:
__cgo_73e035e15f71_Cfunc_pcre_exec in pcre.cgo2.o
(maybe you meant: __cgo_73e035e15f71_Cfunc_pcre_exec)
"_pcre_fullinfo", referenced from:
__cgo_73e035e15f71_Cfunc_pcre_fullinfo in pcre.cgo2.o
(maybe you meant: __cgo_73e035e15f71_Cfunc_pcre_fullinfo)
"_pcre_get_stringnumber", referenced from:
__cgo_73e035e15f71_Cfunc_pcre_get_stringnumber in pcre.cgo2.o
(maybe you meant: __cgo_73e035e15f71_Cfunc_pcre_get_stringnumber)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Iterate over all matches?

Is there a way to iterate over all matches (not capture groups)? SImilar to replaceAll but matchall? I can't figure out how to iterate over them. This package doesnt seem to be active though so I may be out of luck.

What functions does this provide?

This errors:
fmt.Println.Preg_replace('/\s\s+/', ' ', 'Happy Hello')

Since this uses the pcre library, does it use the same function names that PHP uses? Is there an example of how to use this library?

Homebrew install pcre don't work

I used homebrew to install pcre.But when I build my program, I get this error:

pcre.go|52 col 10 error| fatal error: 'pcre.h' file not found

Licence?

Hello,

What type of licence do you apply for this package?

Thanks in avance,

pcre_free

func toheap(ptr *C.pcre) (re Regexp) {
defer C.free(unsafe.Pointer(ptr))
size := pcresize(ptr)
re.ptr = make([]byte, size)
C.memcpy(unsafe.Pointer(&re.ptr[0]), unsafe.Pointer(ptr), size)
return
}

C.free(unsafe.Pointer(ptr)) should use C.pcre_free(unsafe.Pointer(ptr))?

How to replace on match group?

Consider the following interactions, which I assumed would produce identical output, but which do not:

r1 := regexp.MustCompile("a(sd)f")
m1 := r1.ReplaceAll([]byte("asdf"), []byte(" $1 "))
fmt.Printf("[%s]\n", m1) // this produces the correct output: [ sd ]

r2 := pcre.MustCompile("a(sd)f", 0)
m2 := r2.ReplaceAll([]byte("asdf"), []byte(" $1 "), 0)
fmt.Printf("[%s]\n", m2) // this produces incorrect output: [ $1 ]

The first three lines illustrate the behavior of the standard library. The next three illustrate the behavior of this package.

Is there a way to replace on a match group using this library?

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.