Had the need again, found a solution.
Procedure.s
BackrefReplaceRegularExpression( regexp_handle , string.s , replacement.s )
(Limited to three backreferences for I did not need extensive and more clever code)
Code: Select all
ImportC ""
pcre_exec(*pcre,*extra,subject.s,length,startoffset,options,*ovector,ovecsize)
EndImport
Procedure.s BackrefReplaceRegularExpression( regexp_handle , string.s , replacement.s )
Static Dim pcre_results(12)
While pcre_exec(PeekL(regexp_handle),0,string,Len(string),pcre_results(1),0,@pcre_results(),12) > 0
rpl.s = replacement
p=pcre_results(0)
q=pcre_results(1)
If FindString(replacement,"\1",1)
p1=pcre_results(2)
q1=pcre_results(3)
rpl=ReplaceString(rpl,"\1",PeekS(@string+p1,q1-p1))
EndIf
If FindString(replacement,"\2",1)
p1=pcre_results(4)
q1=pcre_results(5)
rpl=ReplaceString(rpl,"\2",PeekS(@string+p1,q1-p1))
EndIf
If FindString(replacement,"\3",1)
p1=pcre_results(6)
q1=pcre_results(7)
rpl=ReplaceString(rpl,"\3",PeekS(@string+p1,q1-p1))
EndIf
string=Left(string,p)+rpl+Right(string,Len(string)-q)
Wend
ProcedureReturn string
EndProcedure
rh = CreateRegularExpression(0," t(.*?)e(.*?) ")
Debug BackrefReplaceRegularExpression(rh,"As they functions tried importing them through the tipteptop","_.T\1E\2._")
@IceSoft: thanks for the feedback. Hope you like my "strategy" in case of need.
(@Fred... should not the original replace function work more this way?)