I got an issue : I'll like to use advanced regex replacements.
Normally when we create a Regex, we can create groups/catches (with parenthesis). Then in Replace functions we can replace a part of the string by a group catch.
In PHP we use "\\x" with x = index of the group. But it doesn't work in PB.
Here is my code :
Code: Select all
Procedure.s Ereg_Replace(Text$, Pattern$, Replace$ = "", Options.l = #PB_RegularExpression_DotAll | #PB_RegularExpression_Extended | #PB_RegularExpression_AnyNewLine)
hRegex = CreateRegularExpression(#PB_Any, Pattern$, Options)
If hRegex
Text$ = ReplaceRegularExpression(hRegex, Text$, Replace$)
FreeRegularExpression(hRegex)
Else
Debug "Can't create a Regex with this pattern : " + Pattern$
EndIf
ProcedureReturn Text$
EndProcedure
; HTML code : removes tags properties (id, class, name, onXXX, ...)
Text$ = "<a onclick='test'></a>"
Text$ = Ereg_Replace(Text$, "<([a-zA-Z]+)\ *[^>]+>", "<\\1>")
Debug Text$
Please share tips/fixes if you have some on it.
Regards
/Lionel