go 导入c的 C.cre2_options_t,暂时没跑完
package main
/*
#cgo LDFLAGS: -lre2 -lcre2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cre2.h>
*/
import (
"C"
"fmt"
"unsafe"
)
func main() {
var (
cre2Opt *C.cre2_options_t
set2 *C.cre2_set
pattern0 = "hello"
pattern1 = "world"
pattern2 = "po.*ar"
pattern3 = "invalid"
match [3]C.int
count C.size_t
)
cre2Opt = (*C.cre2_options_t)(unsafe.Pointer(C.cre2_opt_new()))
set2 = C.cre2_set_new(unsafe.Pointer(cre2Opt), C.CRE2_UNANCHORED)
C.cre2_set_add_simple(set2, C.CString(pattern0))
C.cre2_set_add_simple(set2, C.CString(pattern1))
C.cre2_set_add_simple(set2, C.CString(pattern2))
C.cre2_set_add_simple(set2, C.CString(pattern3))
C.cre2_set_compile(set2)
// Test second match
text := "blabla hello polar bear!"
count = C.cre2_set_match(set2, C.CString(text), C.ulong(len(text)), (*C.int)(unsafe.Pointer(&match)), C.size_t(len(match)))
if count != 2 || match[0] != 0 || match[1] != 2 {
fmt.Printf("Failed to match: %s", text)
} else {
fmt.Printf("Correctly matched: %s\n", text)
}
C.cre2_opt_delete(unsafe.Pointer(cre2Opt))
C.cre2_set_delete(set2)
}
写入自己的博客中才能记得长久
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
2022-03-04 go的rand.Intn()用法和猜年龄, rand.Int()和字符串反转
2022-03-04 go的时间格式和斐波那契函数
2022-03-04 go的字符串处理之分隔