VisualFreeBasic中使用CRegex其实就是vbscript里面的正则,性能比较弱

同时在他的文件头库里面分别有pcre两个版本的bi头文件

只是对应的库没有加进来,本人的主要目的,就是记录这两个pcre库的编译过程,同时也记录几个常见的正则c/c++库

目前PCRE库有两个主版本(major version)。当前的版本,PCRE2的初次发布是在2015年,现在已经到了10.42版了。

更老一点的PCRE版本初次发布时间是1997年,当前仍被广泛的使用,现在已经到了8.45版了。其相应的API及特性当前均已稳定(后续发布也只会进行bug修正)。对于一些新的特性,将会被加入到PCRE2中,而并不会加入到8.x系列中。

本人下载的都是VisualFreeBasic自带头文件的两个版本。

1、pcre8.37

PCRE - Browse /pcre at SourceForge.net

下载之后解压,执行

./configure
make

最后编译好的静态库是libpcre.a(690k)

拷贝到Compile\expand\lib\win32下

由于VisualFreeBasic集成了pcre-8.37的头文件,所以可以直接使用

8.37版本的官方的下载地址是

https://users.freebasic-portal.de/stw/files/prog/fb/libs/pcre-837-static-mingw32.ziphttps://users.freebasic-portal.de/stw/files/prog/fb/libs/pcre-837-static-mingw32.zip

查了一下官方的论坛,后面又出来一个更新的8.39版本

https://users.freebasic-portal.de/stw/files/prog/fb/libs/pcre-839-static.ziphttps://users.freebasic-portal.de/stw/files/prog/fb/libs/pcre-839-static.zip

使用例子

#include Once "pcre.bi"Sub Form1_Shown(hWndForm As hWnd, UserData As Integer)Dim ss As ZString Ptr Dim l As LongDim re As pcre Ptr = pcre_compile(".*", 0, @ss, @l, 0)Dim s As String = "qq"Dim  ovector(30) As Integerpcre_exec(re, 0, @s, Len(s),0,0, @l, 0) Debug.Print *(Cast(ZString Ptr, pcre_version()))
End Sub

编译好体积是228k,体积还是比较理想的。

在Freebasic的论坛找到的正则匹配函数进一步完善

#define PCRE_STATIC
#include Once "pcre.bi"'https://www.pcre.org/original/doc/html/index.html
Function StringRegEx(sPattern As String, sString As String, aArr() As String, iOptions as Ulong = 0, bDebug As Boolean = False) As LongConst iStrVecCnt = 300Dim As Zstring Ptr pErrorStr, pSubStrMatchStrDim As Long iRegexExec, iErrOffset, aStrVec(iStrVecCnt - 1), iResult = -1, i, j = 0, k = 1Dim As pcre_extra tRegexStudyDim As pcre Ptr pRegexCompiledDim As pcre_extra Ptr pRegexStudy'    OPTIONS (second argument) (||'ed together) can be:
'  PCRE_ANCHORED       -- Like adding ^ at start of pattern.
'  PCRE_CASELESS       -- Like m//i
'  PCRE_DOLLAR_ENDONLY -- Make $ match end of string regardless of \n's
'                        No Perl equivalent.
'  PCRE_DOTALL         -- Makes . match newlins too.  Like m//s
'  PCRE_EXTENDED       -- Like m//x
'  PCRE_EXTRA          --
'  PCRE_MULTILINE      -- Like m//m
'  PCRE_UNGREEDY       -- Set quantifiers to be ungreedy.  Individual quantifiers
'                        may be set to be greedy if they are followed by "?".
'  PCRE_UTF8           -- Work with UTF8 strings.'first, the regex string must be compiledpRegexCompiled = pcre_compile(sPattern, iOptions, @pErrorStr,  Cast(Long Ptr, @iErrOffset), 0)If pRegexCompiled = NULL ThenReturn iResultEnd If'optimize the regex'pcre_study() returns NULL for both errors and when it can not optimize the regex.'The last argument is how one checks for errors (it is NULL if everything works, and points to an error string otherwise.pRegexStudy = pcre_study(pRegexCompiled, 0, @pErrorStr)If pRegexStudy = NULL ThenReturn iResult - 1End IfRedim aArr(0 To iStrVecCnt)Do iRegexExec = pcre_exec(pRegexCompiled, pRegexStudy, Strptr(sString), Len(sString), j, 0, Cast(Long Ptr, @aStrVec(0)), iStrVecCnt)If iRegexExec > 0 ThenFor i = 0 To iRegexExec - 1pcre_get_substring(Strptr(sString), @aStrVec(0), iRegexExec, i, @pSubStrMatchStr)If k > Ubound(aArr) Then Redim Preserve aArr(0 To (Ubound(aArr) Shl 1))aArr(k) = pSubStrMatchStr[0]'? aStrVec(i * 2), aStrVec(i * 2 + 1), pSubStrMatchStrk += 1Nextj = aStrVec(1)ElseIf bDebug Then   Select Case iRegexExecCase PCRE_ERROR_NOMATCH? "String did not match the pattern"Case PCRE_ERROR_NULL? "Something was null"Case PCRE_ERROR_BADOPTION? "A bad option was passed"Case PCRE_ERROR_BADMAGIC? "Magic number bad (compiled re corrupt?)"Case PCRE_ERROR_UNKNOWN_NODE? "Something kooky in the compiled re"Case PCRE_ERROR_NOMEMORY? "Ran out of memory"Case Else? "Unknown error"End SelectEndifEndifpcre_free_substring(Cast(Zstring Ptr, @pSubStrMatchStr))Loop Until iRegexExec < 1Redim Preserve aArr(0 To k - 1)pcre_free(pRegexCompiled)#Ifdef PCRE_CONFIG_JITpcre_free_study(pRegexStudy)#Elsepcre_free(pRegexStudy)#Endifpcre_free(pRegexCompiled)aArr(0) = Str(k - 1)Return 1
End Function

但是编译之后会提示

Compile\FREEBA~1.0\bin\win32\ld.exe: CODEGEN_TestPCRE_MAIN.o:fake:(.text+0x747c):Error: 此引用未定义(一般是DLL定义出错) `_imp__pcre_free'

查了一下pcre.bi代码,里面其实就三行代码

#pragma once
#inclib "pcre"
#include once "pcre-common.bi"

进一步查到pcre-common.bi

#if defined(__FB_WIN32__) and (not defined(PCRE_STATIC))extern import pcre_malloc as function(byval as uinteger) as any ptrextern import pcre_free as sub(byval as any ptr)extern import pcre_stack_malloc as function(byval as uinteger) as any ptrextern import pcre_stack_free as sub(byval as any ptr)extern import pcre_callout as function(byval as pcre_callout_block ptr) as longextern import pcre_stack_guard as function() as longextern import pcre16_malloc as function(byval as uinteger) as any ptrextern import pcre16_free as sub(byval as any ptr)extern import pcre16_stack_malloc as function(byval as uinteger) as any ptrextern import pcre16_stack_free as sub(byval as any ptr)extern import pcre16_callout as function(byval as pcre16_callout_block ptr) as longextern import pcre16_stack_guard as function() as longextern import pcre32_malloc as function(byval as uinteger) as any ptrextern import pcre32_free as sub(byval as any ptr)extern import pcre32_stack_malloc as function(byval as uinteger) as any ptrextern import pcre32_stack_free as sub(byval as any ptr)extern import pcre32_callout as function(byval as pcre32_callout_block ptr) as longextern import pcre32_stack_guard as function() as long
#elseextern pcre_malloc as function(byval as uinteger) as any ptrextern pcre_free as sub(byval as any ptr)extern pcre_stack_malloc as function(byval as uinteger) as any ptrextern pcre_stack_free as sub(byval as any ptr)extern pcre_callout as function(byval as pcre_callout_block ptr) as longextern pcre_stack_guard as function() as longextern pcre16_malloc as function(byval as uinteger) as any ptrextern pcre16_free as sub(byval as any ptr)extern pcre16_stack_malloc as function(byval as uinteger) as any ptrextern pcre16_stack_free as sub(byval as any ptr)extern pcre16_callout as function(byval as pcre16_callout_block ptr) as longextern pcre16_stack_guard as function() as longextern pcre32_malloc as function(byval as uinteger) as any ptrextern pcre32_free as sub(byval as any ptr)extern pcre32_stack_malloc as function(byval as uinteger) as any ptrextern pcre32_stack_free as sub(byval as any ptr)extern pcre32_callout as function(byval as pcre32_callout_block ptr) as longextern pcre32_stack_guard as function() as long
#endif

奇怪了,把在Form1中宏定义的

#define PCRE_STATIC
#include Once "pcre.bi"

到了pcre-common.bi就变成没定义了,突然想起了要不把这个宏定义放到起始模块试试

结果换过去瞬间就编译通过了。。

怪不得起始模块上写了这段注释

'************ 应用程序起始模块 ************
' 这里是打开软件后最初被执行代码的地方,此时软件内部还未初始化。(注:一般情况EXE包含DLL的,DLL先于EXE执行DLL自己的起始代码)
' 不管是EXE还是DLL,都从这里开始执行,然后到【程序入口函数】执行,整个软件结束或DLL被卸载就执行【程序出口】过程。(这里的EXE、DLL表示自己程序)
' 一般情况在这里写 DLL 声明、自定义声明、常量和#Include的包含文件。由于很多初始化代码未执行,这里不建议写用户代码。

勇芳诚不欺我也。。

PS:编译之后的程序体积变成了408K,也就是引入正则表达式之后的主程序体积增加了257K。这块不是很满意。。但是想着引入了php和apahce、nginx都使用的正则模块。。忍忍算了。。

2、pcre2-10.20

https://github.com/PCRE2Project/pcre2/

编译方法跟pcre是一样的,只是这个版本更新一些,体积更大,我对程序体积看中,就忽略这个库了

./configure
make

编译出来的libpcre2-8.a体积达到了1101K。

官方的下载地址是

https://users.freebasic-portal.de/stw/files/prog/fb/libs/pcre2-10.36-static.ziphttps://users.freebasic-portal.de/stw/files/prog/fb/libs/pcre2-10.36-static.zip

虽然版本不一样,但是应该能通用的

VisualFreeBasic的pcre/pcre2正则表达式修复相关推荐

  1. linux 卸载 pcre,[Linux] centos误删pcre库如何修复

    首页 专栏 linux 文章详情 0 [Linux] centos误删pcre库如何修复 许可欣 发布于 1 月 25 日 笔者近日配置openresty时误删了pcre库(/lib64/libpcr ...

  2. pcre和正则表达式的误点

    本文只是关于正则一些容易出错的地方,关于正则的学习,可参考如下两篇文章: 基础正则:https://www.cnblogs.com/f-ck-need-u/p/9621130.html Perl正则: ...

  3. python修改字体无效_python正则表达式修复网站文章字体不统一的解决方法

    网站的大框架下有定义的字体,包括字体大小和颜色等,用户发布文章的时候可能是从其他网站复制过来的文本,复制的过程也保留了字体描述信息.当文章在页面上显示的时候,默认先会使用文章中定义的字体,如果文章中字 ...

  4. nginx(五十三)nginx中使用的PCRE正则

    一   pcre 正则语法 说明: 1)从'在nginx中'使用符合'PCRE风格'正则的角度上'学习'2) 部分'案例'比较冷门,不具有'实际'生产意义 PCRE汇总 ①  元字符 说明: 通过'\ ...

  5. 正则表达式学习神器!

    推荐一款优秀的正则表达式在线可视化工具 我相信很多朋友第一次听到正则表达式时,都感觉这是一个高大上的名词. 其实,简单来说,正则表达式就是用来匹配文本的. 正则表达式里的 "正" ...

  6. 4.PHP正则表达式与数组

    PHP正则表达式相关 行定位符 开头 ^tm 结尾 tm$ 不限制 tm 单词定界符 \btm\b   单词tm,如果想取反的话就是大写的 \Btm\B 或的关系,[Tt][Mm] 可以表达 tm T ...

  7. PCRE接口pcre_fullinfo混合子模式调用结果

    NGINX中使用PCRE最为正则表达式的解析接口,对编译和解析过程中的一些点进行了测试验证 PCRE接口pcre_fullinfo()的描述在这个链接中有详细的描述,这里对接口的一些 链接 http: ...

  8. 编程语言和shell编程的基础内容以及grep、egrep命令及相应的正则表达式和用法...

    bash的特性之多命令执行的逻辑关系: 1.命令替换 COMMAND1 $(COMMAND2) 2.管道 COMMAND1 | COMMAND2 | COMMAND3 ... 3.顺序执行结构 COM ...

  9. 梳理正则表达式发展史

    作者:kamly,腾讯 CDC 应用开发工程师 前言 正则表达式在我们日常的软件开发过程中被广泛使用,例如编写 Nginx 配置文件.在 Linux 与 macOS 下查找文件,然而不同软件不同操作系 ...

最新文章

  1. php 腾讯云实时音视频,腾讯云视频 -实时音视频学习日志
  2. 计算机审计应用功能,《计算机审计》模拟试题及答案
  3. 自由落体和抛物线运动
  4. 米家机扫拖机器人说明书_除菌扫拖一次搞定,科沃斯N8除菌扫拖机器人初体验...
  5. 51nod 1270 数组的最大代价 思路:简单动态规划
  6. MFC多文档应用程序同时显示两个视图
  7. 【cocos2d-js官方文档】二十五、Cocos2d-JS v3.0中的单例对象
  8. python爬取数据需要注意的问题
  9. 【原创】不用封装jar包 直接引入工程使用的方法(类似android的 is Library功能)...
  10. vnc 树莓派 链接_树莓派 VNC Viewer 远程桌面配置教程
  11. unittest测试框架详谈及实操(一)
  12. 农民工兄弟学C#(4)
  13. 软件工程——软件计划
  14. 六、CSS3的美化字体与段落
  15. 如何格式化小米云服务器,互联网要点:怎么把小米手机格式化(恢复出厂设置)...
  16. 怎么监控mysql数据变化_mysql数据库数据变化实时监控
  17. 超好用的手机录屏软件推荐
  18. 一篇让你熟练掌握Google Guava包(全网最全)
  19. 图像处理基础之颜色空间
  20. python_1.统计字符串中,中文字符,英文字符、数字、空格和其他字符的个数?

热门文章

  1. 中科院又立大功!14nm国产芯片将量产
  2. WEB Basic基础-07
  3. 【技术认证题库】SCCA理论AD考试【初级】
  4. Linux | Linux系统目录
  5. 深度分析:传统企业如何通过开源信息化平台成功实现数字化转型
  6. android 输入法 智能abc 风格,云风的 BLOG
  7. DNS错误怎么办(如何正确设置DNS)
  8. java核心技术精讲-李兴华-专题视频课程
  9. 前端面试题(Vue)
  10. 网页(浏览器)调用本地exe应用软件