Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 6.19 KB | None | 0 0
  1. <%
  2. If Request.Form("matchortest") = "match" then
  3.   Session("match")="checked"
  4.   Session("test")=""
  5.   Session("replace")=""
  6. End if
  7. If Request.Form("matchortest") = "test" then
  8.   Session("match")=""
  9.   Session("test")="checked"
  10.   Session("replace")=""
  11. End if
  12. If Request.Form("matchortest") = "replace" then
  13.   Session("match")=""
  14.   Session("test")=""
  15.   Session("replace")="checked"
  16. End if
  17. Session("teststring")=Request.Form("teststring")
  18. Session("testpattern")=Request.Form("testpattern")
  19. Session("replacement")=Request.Form("replacement")
  20. Session("ignorecase")=Request.Form("ignorecase")
  21. Session("multiline")=Request.Form("multiline")
  22. response.write "<html><head><title>Classic ASP Regex Tester</title></head><body bgcolor='#C0C0C0'><form method='POST' action='regextester.asp?submit=yes'>"
  23. response.write "Test String:<br><textarea style='background-color:#FFFFCC;' name='teststring' cols=120 rows=20 tabindex=1>" & Server.HTMLEncode(Session("teststring")) & "</textarea><br>"
  24. response.write "Match Pattern:<br><textarea style='background-color:#FFFFCC;' name='testpattern' cols=120 rows=8 tabindex=2>"  & Server.HTMLEncode(Session("testpattern")) & "</textarea><br>"
  25. response.write "Replacement Pattern:<br><textarea style='background-color:#CCFFFF;' name='replacement' cols=120 rows=1 tabindex=2>"  & Server.HTMLEncode(Session("replacement")) & "</textarea><br>"
  26. response.write "<input type='radio' name='matchortest' "
  27. If Request.QueryString("submit") = "yes" then
  28.   Response.Write Session("match")
  29. Else
  30.   Response.Write "checked"
  31. End If
  32. Response.write " tabindex=3 value='match'>Match"
  33. response.write "<input type='radio' name='matchortest' "
  34. If Request.QueryString("submit") = "yes" then
  35.   Response.Write Session("replace")
  36. End If
  37. Response.write " tabindex=4 value='replace'>Replace"
  38. response.write "<input type='radio' name='matchortest' "
  39. If Request.QueryString("submit") = "yes" then
  40.   Response.Write Session("test")
  41. End If
  42. Response.write " tabindex=5 value='test'>Test"
  43. response.write "<input type='checkbox' name='ignorecase' "
  44. If Request.QueryString("submit") = "yes" then
  45.   Response.Write Session("ignorecase")
  46. Else
  47.   Response.Write "checked"
  48. End If
  49. Response.write " tabindex=6 value='checked'>Ignore Case"
  50. response.write "<input type='checkbox' name='multiline' "
  51. If Request.QueryString("submit") = "yes" then
  52.   Response.Write Session("multiline")
  53. Else
  54.   Response.Write "checked"
  55. End If
  56. Response.write " tabindex=7 value='checked'>Multi Line&nbsp;"
  57. response.write "<input type='submit' value='Submit' tabindex=7 name='B1'>&nbsp;&nbsp;<input type='reset' tabindex=6 value='Reset' onclick=" & chr(34) & "location.href='regextester.asp?submit=clear';" & chr(34) & " name='B2'>"
  58. If Request.QueryString("submit") = "yes" then
  59.   Response.write "<br>ASP Code:"
  60.   set regEx = New Regexp
  61.   regEx.Pattern = Request.Form("testpattern")
  62.   regEx.Global = true
  63.   if Session("ignorecase") = "checked" then
  64.     regEx.IgnoreCase = True
  65.     ignorecase = "True"
  66.   else
  67.     regEx.IgnoreCase = False
  68.     ignorecase = "False"
  69.   end if
  70.   if Session("multiline") = "checked" then
  71.     regEx.MultiLine = True
  72.     multiline = "True"
  73.   else
  74.     regEx.MultiLine = False
  75.     multiline = "False"
  76.   end if
  77.   TestStr = "<your string>"
  78.   regstring = "Set regEx = New RegExp" & vbcrlf & "regEx.Global = True" & vbcrlf & "regEx.IgnoreCase = " & ignorecase & vbcrlf & "regEx.MultiLine = " & multiline & vbcrlf & "teststring = " & chr(34) & TestStr & chr(34) & vbcrlf & "regEx.Pattern = " & chr(34) & Server.HTMLEncode(Replace(Request.Form("testpattern"),chr(34),chr(34) & chr(34))) & chr(34) & vbcrlf
  79.   If Session("match") = "checked" then
  80.     Set Matches = regEx.Execute(Request.Form("teststring"))
  81.     regstring = regstring & "Set Matches = regEx.Execute(teststring)"
  82.     Response.write "<br><textarea style='background-color:#FFFFCC;' cols=120 rows=7>" & regstring & "</textarea>"
  83.     lines=1
  84.     For z = 0 to Matches.Count-1
  85.       AllSub = AllSub & "Matches(" & z & ") = " & chr(34) & Server.HTMLEncode(Matches(z)) & chr(34) & chr(13)
  86.       For zz = 0 to Matches(z).SubMatches.Count-1
  87.         AllSub = AllSub & "Matches(" & z & ").SubMatches(" & zz & ") = " & chr(34) & Server.HTMLEncode(Matches(z).SubMatches(zz)) & chr(34) & chr(13)
  88.       next
  89.       AllSub=Left(AllSub,Len(AllSub)-1) & chr(13)
  90.       lines=lines+Matches(z).SubMatches.Count+1
  91.     next
  92.     If len(AllSub)>1 then
  93.         AllSub=Left(AllSub,Len(AllSub)-1)
  94.     End If
  95.     lines=lines-1
  96.     If Matches.Count > 0 then
  97.       Response.write "<br>Results:<br><textarea style='background-color:#FFFFCC;' name='AllSub' cols=120 rows=" & lines+5 & " tabindex=99>"  & AllSub & "</textarea><br>"
  98.     Else
  99.       Response.write "<br>Results:<br><textarea style='background-color:#FFFFCC;' name='AllSub' cols=120 rows=1 tabindex=99><<No Matches>></textarea>"
  100.     End if
  101.   Elseif Session("replace") = "checked" then
  102.     regstring = regstring & "replacementstring = " & chr(34) & Server.HTMLEncode(Replace(Request.Form("replacement"),chr(34),chr(34) & chr(34))) & chr(34) & vbcrlf & "teststring = regEx.Replace(teststring,replacementstring)"
  103.     Response.write "<br><textarea style='background-color:#FFFFCC;' cols=120 rows=8>" & regstring & "</textarea><br>"
  104.     teststring1 = Request.Form("teststring")
  105.     replacement1 = Request.Form("replacement")
  106.     Result = regEx.Replace(teststring1,replacement1)
  107.     Result = Server.HTMLEncode(Result)
  108.     Response.write "Results:<br><textarea style='background-color:#FFFFCC;' name='AllSub' cols=120 rows=7 tabindex=99>" & Result & "</textarea>"
  109.   Elseif Session("test") = "checked" then
  110.     Test = regEx.Test(Request.Form("teststring"))
  111.     if len(Request.Form("teststring")) < 35 then
  112.       TestStr = replace(Request.Form("teststring"),chr(34),chr(34) & chr(34))
  113.     else
  114.       TestStr = "<your string>"
  115.     end if
  116.     regstring = regstring & "Set Test = regEx.Test(teststring)"
  117.     Response.write "<br><textarea style='background-color:#FFFFCC;' cols=120 rows=7>" & regstring & "</textarea><br>"
  118.     Response.write "Results:<br><textarea style='background-color:#FFFFCC;' name='AllSub' cols=120 rows=1 tabindex=99>regEx.Test(teststring) = "  & Test & "</textarea>"
  119.   End if
  120.   Response.write "</form></body></html>"
  121. End If
  122. Set regEx=NOTHING
  123. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement