Regular Expression dude
Posted: Thu Dec 13, 2018 6:44 pm
Hi, In Notepad++ I can do this search/replace:
Find: <a [[:<:]]href(.*?)<\/a>
Replace with: <zz href$1</zz>
And it will change all <a href...>I'm a phrase</a> tags in a document to <zz href...>I'm a phrase</zz>
<a href=\"https://www.sample.com\">I'm a phrase</a> will be replace to
<zz href=\"https://www.sample.com\">I'm a phrase</zz>
(I don't want to change pairs without href attribute, as <a noPop" onClick="var e=document.createElement('script');>Another phrase</a>)
How can I do it in pb? Actually I use this code
Thank you and sorry my english!
Find: <a [[:<:]]href(.*?)<\/a>
Replace with: <zz href$1</zz>
And it will change all <a href...>I'm a phrase</a> tags in a document to <zz href...>I'm a phrase</zz>
<a href=\"https://www.sample.com\">I'm a phrase</a> will be replace to
<zz href=\"https://www.sample.com\">I'm a phrase</zz>
(I don't want to change pairs without href attribute, as <a noPop" onClick="var e=document.createElement('script');>Another phrase</a>)
How can I do it in pb? Actually I use this code
Code: Select all
Procedure.s Ereg_Replace(Text$, Pattern$, Replace$ = "", Options.l = #PB_RegularExpression_DotAll | #PB_RegularExpression_Extended | #PB_RegularExpression_AnyNewLine)
Protected hRegex = CreateRegularExpression(#PB_Any, Pattern$, Options)
Protected Dim result.s(0)
If hRegex
Repeat
ReDim result(0)
ExtractRegularExpression(hRegex, Text$, result())
Text$ = ReplaceRegularExpression(hRegex, Text$, Replace$)
Delay(0)
Until ArraySize(result())=0
FreeRegularExpression(hRegex)
Else
Debug "Can't create a Regex with this pattern : " + Pattern$
EndIf
ProcedureReturn Text$
EndProcedure
Text$ = ~"<a href=\"https://www.sample.com\">I'm a phrase</a>"
Debug Ereg_Replace(Text$, "<a href(.*?)<\/a>", "<zz href$1</zz>", #PB_RegularExpression_DotAll|#PB_RegularExpression_MultiLine|#PB_RegularExpression_NoCase)