Code: Select all
754'536 <a href="https://purebasic.com">PB</a>, 523'434 <a href='https://purebasic.com'>PB</a> 837'562Code: Select all
754'536 <a href="https://purebasic.com">PB</a>, 523'434 <a href="https://purebasic.com">PB</a> 837'562
Code: Select all
754'536 <a href="https://purebasic.com">PB</a>, 523'434 <a href='https://purebasic.com'>PB</a> 837'562Code: Select all
754'536 <a href="https://purebasic.com">PB</a>, 523'434 <a href="https://purebasic.com">PB</a> 837'562
Code: Select all
Procedure.s ConformAllHyperlinks(h.s)
Static r.i
If Not r
r = CreateRegularExpression(#PB_Any,"href='(.+?)'")
EndIf
If ExamineRegularExpression(r,h)
While NextRegularExpressionMatch(r)
detect1 = RegularExpressionMatchPosition(r)
detect2 = RegularExpressionMatchLength(r)
tag.s = Mid(h,detect1,detect2)
tag = ReplaceString(tag,Chr(39),Chr(34))
h = Left(h,detect1-1)+tag+Mid(h,detect1+detect2,Len(h))
Wend
EndIf
ProcedureReturn h
EndProcedureCode: Select all
; https://www.purebasic.fr/english/viewtopic.php?p=575871
Structure ReplaceGr : pos.i : ngr.i : group.s : EndStructure
Procedure RegexReplace2(RgEx, *Result.string, Replace0$)
Protected i, CountGr, Pos, Offset = 1
Protected Replace$
Protected NewList item.s()
Protected LenT, *Point
Protected RE2
Protected NewList ReplaceGr.ReplaceGr()
CountGr = CountRegularExpressionGroups(RgEx):If CountGr > 9:CountGr = 9 :EndIf ; max 9 groups
If ExamineRegularExpression(RgEx, *Result\s)
RE2 = CreateRegularExpression(#PB_Any, "\\\d")
If RE2
If ExamineRegularExpression(RE2, Replace0$)
While NextRegularExpressionMatch(RE2)
If AddElement(ReplaceGr())
ReplaceGr()\pos = RegularExpressionMatchPosition(RE2) ; позиция
ReplaceGr()\ngr = ValD(Right(RegularExpressionMatchString(RE2), 1)) ; номер группы
ReplaceGr()\group = RegularExpressionMatchString(RE2) ; текст группы
EndIf
Wend
EndIf
FreeRegularExpression(RE2) ; убрать строку при Static
EndIf
If Not ListSize(ReplaceGr())
*Result\s = ReplaceRegularExpression(RgEx, *Result\s, Replace0$)
ProcedureReturn
EndIf
SortStructuredList(ReplaceGr(), #PB_Sort_Descending, OffsetOf(ReplaceGr\pos), TypeOf(ReplaceGr\pos))
While NextRegularExpressionMatch(RgEx)
Pos = RegularExpressionMatchPosition(RgEx)
Replace$ = Replace0$
ForEach ReplaceGr()
If ReplaceGr()\ngr
Replace$ = ReplaceString(Replace$, ReplaceGr()\group, RegularExpressionGroup(RgEx, ReplaceGr()\ngr), #PB_String_NoCase, ReplaceGr()\pos, 1)
Else
Replace$ = ReplaceString(Replace$, ReplaceGr()\group, RegularExpressionMatchString(RgEx), #PB_String_NoCase, ReplaceGr()\pos, 1) ; обратная ссылка \0
EndIf
Next
If AddElement(item())
item() = Mid(*Result\s, Offset, Pos - Offset) + Replace$
EndIf
Offset = Pos + RegularExpressionMatchLength(RgEx)
Wend
If AddElement(item())
item() = Mid(*Result\s, Offset)
EndIf
LenT = 0
ForEach item()
LenT + Len(item()) ; вычисляем длину данных для вмещения частей текста
Next
*Result\s = Space(LenT) ; создаём строку забивая её пробелами
*Point = @*Result\s ; Получаем адрес строки
ForEach item()
CopyMemoryString(item(), @*Point) ; копируем очередной путь в указатель
Next
FreeList(item()) ; удаляем список, хотя в функции наверно это не требуется
EndIf
EndProcedure
Define Text.string
Text\s = ~"754'536 <a href=\"https://purebasic.com\">PB</a>, 523'434 <a href='https://purebasic.com'>PB</a> 837'562"
CreateRegularExpression(0 , "(.*href=)'(.+?)'(.*)" )
RegexReplace2(0, @Text, ~"\\1\"\\2\"\\3" )
FreeRegularExpression(0)
Debug Text\sDo I have it? No.