"----------------------------------" Her starter min funktion <%
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 & "'." 'print 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!"'.
"-----------------------------------"
Men hvordan får jeg lavet en replace funktion så jeg får et nyt output som ligner nedenstående.
Jeg ønsker blot at erstatte !moduleStart!newsletter(37)!moduleEnd!
Noget i den her stil?? Kan ikke få det til at virke...
sNewHTML = Request.Form("inpContent")
Function ReplaceTest(patrn, replStr) Dim regEx, str1 ' Create variables. str1 = sNewHTML Set regEx = New RegExp ' Create regular expression. regEx.Pattern = patrn ' Set pattern. regEx.IgnoreCase = True ' Make case insensitive. set matches = regEx.Replace(str1, replStr) ' set matches til at finde alle emner
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 Function
JA det virker i al fald ikke... hvis jeg gør sådan her:
Function ReplaceTest(patrn, replStr) Dim regEx, str1 ' Create variables. str1 = sNewHTML Set regEx = New RegExp ' Create regular expression. regEx.Pattern = patrn ' Set pattern. regEx.IgnoreCase = True ' Make case insensitive. ReplaceTest = regEx.Replace(str1, replStr) ' set matches til at finde alle emner
Function ReplaceTest(patrn, replStr) Dim regEx, str1 ' Create variables. str1 = sNewHTML Set regEx = New RegExp ' Create regular expression. regEx.Global = true regEx.Pattern = patrn ' Set pattern. regEx.IgnoreCase = True ' Make case insensitive. ReplaceTest = regEx.Replace(str1, replStr) ' set matches til at finde alle emner
Du skal blot overveje om du har brug for: regEx.IgnoreCase = True
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.