Page 1 of 1
It is not possible in PB REGXP? <a\shref="(.*)?pcre.
Posted: Sat Dec 27, 2008 2:12 am
by zxtunes.com
I have this regular expression:
Code: Select all
<a\shref="(.*)?pcre.ru(.*)?>(.*)?<\/a>
[/b]
and test text sample "
<a href="http://www.pcre.ru/bla">text</a>".
It work in perl, php, and online designer of regular expression (
http://www.pcre.ru/eval/).
Screenshot what it work:
I tried to write such code, but it does not work:
Code: Select all
If CreateRegularExpression(0, "<a\shref='(.*)?pcre.ru(.*)?>(.*)?<\/a>")
Dim Result$(0)
NbFound = ExtractRegularExpression(0, "<a href='http://www.pcre.ru/bla'>text</a>", Result$())
For k = 0 To NbFound-1
Debug Result$(k)
Next
Else
Debug RegularExpressionError()
EndIf

Posted: Sat Dec 27, 2008 2:54 pm
by hallodri
versuch mal das :
Code: Select all
ImportC ""
pcre_exec(*pcre,*extra,subject.s,length,startoffset,options,*ovector,ovecsize)
pcre_get_substring(subject.s,*ovector,stringcount,stringnumber,stringptr)
pcre_free_substring(stringptr)
EndImport
Procedure.s getSubstring(subject.s,count,ov,substring)
Protected buffer.i
Protected string.s = ""
pcre_get_substring(subject, ov, count, substring, @buffer)
If (buffer)
string = PeekS(buffer)
pcre_free_substring(buffer)
EndIf
ProcedureReturn string
EndProcedure
; 1 2 3
Define pattern.s = "<a\shref='(.*)?pcre.ru(.*)?>(.*)?<\/a>"
Define subject.s = "<a href='http://www.pcre.ru/bla'>text</a>"
Define len = Len(subject)
Dim ovec(30)
regex = CreateRegularExpression(#PB_Any, pattern)
count = pcre_exec(PeekL(regex), 0, subject, len, 0, 0, @ovec(), 30)
For i = 1 To 3
Debug getSubstring(subject,count,ovec(),i)
Next
Posted: Sat Dec 27, 2008 3:30 pm
by zxtunes.com
Thanks
hallodri!!
This interesting decision.
But it does not work in "unicode executable".

Posted: Sat Dec 27, 2008 3:43 pm
by hallodri
and this ?
Code: Select all
ImportC ""
pcre_exec(*pcre,*extra,subject.p-ascii,length,startoffset,options,*ovector,ovecsize)
pcre_get_substring(subject.p-ascii,*ovector,stringcount,stringnumber,stringptr)
pcre_free_substring(stringptr)
EndImport
Procedure.s getSubstring(subject.s,count,ov,substring)
Protected buffer.i
Protected string.s = ""
pcre_get_substring(subject, ov, count, substring, @buffer)
If (buffer)
string = PeekS(buffer,#PB_Any,#PB_Ascii)
pcre_free_substring(buffer)
EndIf
ProcedureReturn string
EndProcedure
Posted: Sat Dec 27, 2008 3:53 pm
by zxtunes.com
hallodri wrote:and this ?
It works if not to use only Russian symbols, differently gives out empty lines.
Probably problem "subject.p-ascii"? but I not so understand that it.
It not work in standart mode too (if use Russian symbols). However PB RegularExpression command work with Russian symbols in both modes.
Posted: Sat Dec 27, 2008 3:59 pm
by eddy
subject.p-unicode
Posted: Sat Dec 27, 2008 4:02 pm
by zxtunes.com
eddy wrote:subject.p-unicode
Too does not work.

Posted: Sat Dec 27, 2008 4:22 pm
by eddy
try this one
Code: Select all
ImportC ""
pcre_exec(*pcre, *extra, subject.p-utf8, length, startoffset, options, *ovector, ovecsize)
pcre_get_substring(subject.p-utf8, *ovector, stringcount, stringnumber, stringptr)
pcre_free_substring(stringptr)
EndImport
Procedure.s getSubstring(subject.s, count, ov, substring)
Protected buffer.i
Protected string.s = ""
pcre_get_substring(subject, ov, count, substring, @buffer)
If (buffer)
string = PeekS(buffer,-1,#PB_UTF8)
pcre_free_substring(buffer)
EndIf
ProcedureReturn string
EndProcedure
; 1 2 3
Define pattern.s = "<a\shref='(.*)?pcre.ru(.*)?>(.*)?<\/a>"
Define subject.s = "<a href='http://www.pcre.ru/bla'>text</a>"
Define len =Len(subject)
Dim ovec(30)
regex = CreateRegularExpression(#PB_Any, pattern)
count = pcre_exec(PeekL(regex), 0, subject, len, 0, 0, @ovec(), ArraySize(ovec()))
For i = 1 To 3
Debug getSubstring(subject, count, ovec(), i)
Next
Posted: Sat Dec 27, 2008 5:54 pm
by zxtunes.com
eddy wrote:try this one
Not work.
Try replace "
<a href='http://www.pcre.ru/bla'>[u]text[/u]</a>" for "
<a href='http://www.pcre.ru/bla'>[u]français[/u]</a>" and compiled in "unicode executable",
for you works?