It is not possible in PB REGXP? <a\shref="(.*)?pcre.

Just starting out? Need help? Post your questions and find answers here.
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

It is not possible in PB REGXP? <a\shref="(.*)?pcre.

Post 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:

Image

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
:cry:
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Post 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   

User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Post by zxtunes.com »

Thanks hallodri!!

This interesting decision.

But it does not work in "unicode executable". :oops:
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Post 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
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Post 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.
Last edited by zxtunes.com on Sat Dec 27, 2008 4:00 pm, edited 1 time in total.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

subject.p-unicode
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Post by zxtunes.com »

eddy wrote:subject.p-unicode
Too does not work. :cry:
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post 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
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Post 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?
Post Reply