glenn-brown / golang-pkg-pcre Goto Github PK
View Code? Open in Web Editor NEWPerl Compatible Regular Expression shim for Go
Perl Compatible Regular Expression shim for Go
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
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 (Matches
instead 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.
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
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)
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.
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?
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
Hello,
What type of licence do you apply for this package?
Thanks in avance,
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))?
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.