强大的正则表达式库PCRE 汇编调用试例

 

PCRE(Perl Compatible Regular Expressions中文含义:perl语言兼容正则表达式)是一个用C语言编写的正则表达式函数库,由菲利普.海泽(Philip Hazel)编写。PCRE是一个轻量级的函数库,比Boost之中的正则表达式库小得多。PCRE十分易用,同时功能也很强大,性能超过了POSIX正则表达式库和一些经典的正则表达式库。linux 下很多款软件都依赖 PCRE 来做正则表达式判断。
-----------------------------------------------------------
Hi
For a project I’m working on I needed the PCRE library. I looked on the official site and quickly found out that there is no updated static library around to download. After spending some hours with VS9 I noticed that VS6 was a much better choice because of header dependencies. Finally I got a compiled static library that works fine with masm.

Biterider     2010-10-15 14:50:59
-----------------------------------------------------------
嗯,就用Biterider编译好的pcre81s.lib库(自己也很容易编译哦^_^),感谢,呵呵。
我就给一个小的例子吧,更多的说明请参看pcre的官网,google第一个就是的。

 

;************************************************************
;*--==--* Simple asm program to call pcre lib.
;*--==--* By G-Spider 2010.11.28
;*--==--* Web:http://blog.csdn.net/G_Spider
;*--==--* ---------------------------------------------------
;*--==--* ml  /c /coff asmpcre.asm 
;*--==--* link /subsystem:console asmpcre.obj
;************************************************************

 .386
 .model flat,stdcall
 option casemap:none
 
 include windows.inc
 include user32.inc
 include kernel32.inc
 include msvcrt.inc
 include PCRE81S.inc    ;<-------
 
 includelib user32.lib
 includelib kernel32.lib
 includelib msvcrt.lib
 includelib PCRE81S.lib ;<-------       
 
OVECCOUNT       equ     30 ;/* should be a multiple of 3 */
EBUFLEN         equ     128
BUFLEN          equ     1024
;***********************************************************;
.data
       
        szSrc           db      ' href=http://blog.csdn.net/G_Spider+c%2B%2B+',0
        szPattern       db      'http://(.*)(..Spider)',0
       
        szovector       db      'szovector[]= ',0dh,0ah,0
       
        fmt1            db      'String : %s',0dh,0ah,0
        fmt2            db      'Pattern: %s',0dh,0ah,0dh,0ah,0
        fmt3            db      '%d ',0
        fmt4            db      'Return pattern string:',0dh,0ah,0dh,0ah,0
        fmt5            db      '%s',0dh,0ah,0
        szPause         db      'Pause',0
      

.data?
        _error          dd      ?
        erroffset       dd      ?
        ovector         dd      OVECCOUNT   dup(?)
        rc              dd      ?
        result          dd      ?           
 

;***********************************************************
.code
;-----------------------------------------------------------
start:
        invoke  crt_printf,offset fmt1,offset szSrc
        invoke  crt_printf,offset fmt2,offset szPattern
        invoke  pcre_compile,offset szPattern,0,offset _error,offset erroffset,0
        .if     eax==NULL
                invoke MessageBox,NULL,0,0,0
                ret
        .endif
        invoke  pcre_exec,eax,0,offset szSrc,sizeof szSrc,0,0,offset ovector,OVECCOUNT
        ;匹配成功返回匹配数,没有匹配返回-1
        mov     rc,eax
        mov     edx,eax
        and     edx,80000000h
        .if     edx!=0
                invoke  crt_printf,offset fmt3,eax
                invoke  MessageBox,NULL,0,0,0
                invoke ExitProcess,0
        .endif
       
        invoke  crt_printf,offset fmt4
        xor     eax,eax ;eax=1?              
        .while  eax<rc              
                push    eax
                invoke  pcre_get_substring,offset szSrc,offset ovector,rc,eax,offset result
                invoke  crt_printf,offset fmt5,result
                pop     eax
                inc     eax

        .endw       
                ;int pcre_get_substring(const char *subject, int *ovector,
                ;int stringcount, int stringnumber,
                ;const char **stringptr)
               
        invoke  crt_printf,offset szovector
        xor     eax,eax
        .while  eax<OVECCOUNT
                push    eax
                invoke  crt_printf,offset fmt3,ovector[4*eax]
                pop     eax
                inc     eax
        .endw
              
        invoke  pcre_free,rc
        invoke  crt_system,offset szPause
 invoke ExitProcess,0
end start

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值