Hjælp til RegExp
Hej,Jeg ønsker at lave en søg og erstat funktion, som erstatter noget af mit input.
inpContent består af eks:
<p>Kontaktformular</p>
<p>
<img alt="!moduleStart!contactform(79)!moduleEnd!" src="/admin/editor/scripts/module.gif" />
</p>
<p>Billede galleri</p>
<p>
<img alt="!moduleStart!gallery(25)!moduleEnd!" src="/admin/editor/scripts/module.gif" />
</p>
<p> Nyhedsbrev</p>
<p>
<img alt="!moduleStart!newsletter(37)!moduleEnd!" src="/admin/editor/scripts/module.gif" />
</p>
' First step is to remove the module image tag and replace it by real ASP code.
webSiteContent = Request.Form("inpContent")
'this sub finds the matches
Sub RegExpTest(strMatchPattern, strPhrase)
'create variables
Dim objRegEx, Match, Matches, StrReturnStr
'create instance of RegExp object
Set objRegEx = New RegExp
'find all matches
objRegEx.Global = True
'set case insensitive
objRegEx.IgnoreCase = True
'set the pattern
objRegEx.Pattern = strMatchPattern
'create the collection of matches
Set Matches = objRegEx.Execute(strPhrase)
'print out all matches
For Each Match in Matches
strReturnStr = "Match found at position "
strReturnStr = strReturnStr & Match.FirstIndex & "." & Match
'Value is '"
strReturnStr = strReturnStr & Match.value & "'."
Response.Write(strReturnStr & "<BR>")
Next
End Sub
'call the subroutine
regExpTest "!moduleStart!([\s\S]+?)!moduleEnd!.", webSiteContent
Jeg får også output ud:
Match found at position 46.!moduleStart!contactform(79)!moduleEnd!"!moduleStart!contactform(79)!moduleEnd!"'.
Match found at position 179.!moduleStart!gallery(25)!moduleEnd!"!moduleStart!gallery(25)!moduleEnd!"'.
Match found at position 303.!moduleStart!newsletter(37)!moduleEnd!"!moduleStart!newsletter(37)!moduleEnd!"'.
Hvis jeg nu ønsker at replace det output så jeg får
<p>Kontaktformular</p>
<p>
<% call contactform(79) %>
</p>
<p>Billede galleri</p>
<p>
<% call gallery(25) %>
</p>
<p> Nyhedsbrev</p>
<p>
<% call newsletter(37)
</p>