強大的Regex庫PCRE 彙編調用試例

來源:互聯網
上載者:User
 

PCRE(Perl Compatible Regular Expressions中文含義:perl語言相容Regex)是一個用C語言編寫的Regex函數庫,由菲利普.海澤(Philip Hazel)編寫。PCRE是一個輕量級的函數庫,比Boost之中的Regex庫小得多。PCRE十分易用,同時功能也很強大,效能超過了POSIXRegex庫和一些經典的Regex庫。linux 下很多款軟體都依賴 PCRE 來做Regex判斷。
-----------------------------------------------------------
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

 

 

 

 

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.