Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%
- If Request.Form("matchortest") = "match" then
- Session("match")="checked"
- Session("test")=""
- Session("replace")=""
- End if
- If Request.Form("matchortest") = "test" then
- Session("match")=""
- Session("test")="checked"
- Session("replace")=""
- End if
- If Request.Form("matchortest") = "replace" then
- Session("match")=""
- Session("test")=""
- Session("replace")="checked"
- End if
- Session("teststring")=Request.Form("teststring")
- Session("testpattern")=Request.Form("testpattern")
- Session("replacement")=Request.Form("replacement")
- Session("ignorecase")=Request.Form("ignorecase")
- Session("multiline")=Request.Form("multiline")
- response.write "<html><head><title>Classic ASP Regex Tester</title></head><body bgcolor='#C0C0C0'><form method='POST' action='regextester.asp?submit=yes'>"
- response.write "Test String:<br><textarea style='background-color:#FFFFCC;' name='teststring' cols=120 rows=20 tabindex=1>" & Server.HTMLEncode(Session("teststring")) & "</textarea><br>"
- response.write "Match Pattern:<br><textarea style='background-color:#FFFFCC;' name='testpattern' cols=120 rows=8 tabindex=2>" & Server.HTMLEncode(Session("testpattern")) & "</textarea><br>"
- response.write "Replacement Pattern:<br><textarea style='background-color:#CCFFFF;' name='replacement' cols=120 rows=1 tabindex=2>" & Server.HTMLEncode(Session("replacement")) & "</textarea><br>"
- response.write "<input type='radio' name='matchortest' "
- If Request.QueryString("submit") = "yes" then
- Response.Write Session("match")
- Else
- Response.Write "checked"
- End If
- Response.write " tabindex=3 value='match'>Match"
- response.write "<input type='radio' name='matchortest' "
- If Request.QueryString("submit") = "yes" then
- Response.Write Session("replace")
- End If
- Response.write " tabindex=4 value='replace'>Replace"
- response.write "<input type='radio' name='matchortest' "
- If Request.QueryString("submit") = "yes" then
- Response.Write Session("test")
- End If
- Response.write " tabindex=5 value='test'>Test"
- response.write "<input type='checkbox' name='ignorecase' "
- If Request.QueryString("submit") = "yes" then
- Response.Write Session("ignorecase")
- Else
- Response.Write "checked"
- End If
- Response.write " tabindex=6 value='checked'>Ignore Case"
- response.write "<input type='checkbox' name='multiline' "
- If Request.QueryString("submit") = "yes" then
- Response.Write Session("multiline")
- Else
- Response.Write "checked"
- End If
- Response.write " tabindex=7 value='checked'>Multi Line "
- response.write "<input type='submit' value='Submit' tabindex=7 name='B1'> <input type='reset' tabindex=6 value='Reset' onclick=" & chr(34) & "location.href='regextester.asp?submit=clear';" & chr(34) & " name='B2'>"
- If Request.QueryString("submit") = "yes" then
- Response.write "<br>ASP Code:"
- set regEx = New Regexp
- regEx.Pattern = Request.Form("testpattern")
- regEx.Global = true
- if Session("ignorecase") = "checked" then
- regEx.IgnoreCase = True
- ignorecase = "True"
- else
- regEx.IgnoreCase = False
- ignorecase = "False"
- end if
- if Session("multiline") = "checked" then
- regEx.MultiLine = True
- multiline = "True"
- else
- regEx.MultiLine = False
- multiline = "False"
- end if
- TestStr = "<your string>"
- 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
- If Session("match") = "checked" then
- Set Matches = regEx.Execute(Request.Form("teststring"))
- regstring = regstring & "Set Matches = regEx.Execute(teststring)"
- Response.write "<br><textarea style='background-color:#FFFFCC;' cols=120 rows=7>" & regstring & "</textarea>"
- lines=1
- For z = 0 to Matches.Count-1
- AllSub = AllSub & "Matches(" & z & ") = " & chr(34) & Server.HTMLEncode(Matches(z)) & chr(34) & chr(13)
- For zz = 0 to Matches(z).SubMatches.Count-1
- AllSub = AllSub & "Matches(" & z & ").SubMatches(" & zz & ") = " & chr(34) & Server.HTMLEncode(Matches(z).SubMatches(zz)) & chr(34) & chr(13)
- next
- AllSub=Left(AllSub,Len(AllSub)-1) & chr(13)
- lines=lines+Matches(z).SubMatches.Count+1
- next
- If len(AllSub)>1 then
- AllSub=Left(AllSub,Len(AllSub)-1)
- End If
- lines=lines-1
- If Matches.Count > 0 then
- Response.write "<br>Results:<br><textarea style='background-color:#FFFFCC;' name='AllSub' cols=120 rows=" & lines+5 & " tabindex=99>" & AllSub & "</textarea><br>"
- Else
- Response.write "<br>Results:<br><textarea style='background-color:#FFFFCC;' name='AllSub' cols=120 rows=1 tabindex=99><<No Matches>></textarea>"
- End if
- Elseif Session("replace") = "checked" then
- 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)"
- Response.write "<br><textarea style='background-color:#FFFFCC;' cols=120 rows=8>" & regstring & "</textarea><br>"
- teststring1 = Request.Form("teststring")
- replacement1 = Request.Form("replacement")
- Result = regEx.Replace(teststring1,replacement1)
- Result = Server.HTMLEncode(Result)
- Response.write "Results:<br><textarea style='background-color:#FFFFCC;' name='AllSub' cols=120 rows=7 tabindex=99>" & Result & "</textarea>"
- Elseif Session("test") = "checked" then
- Test = regEx.Test(Request.Form("teststring"))
- if len(Request.Form("teststring")) < 35 then
- TestStr = replace(Request.Form("teststring"),chr(34),chr(34) & chr(34))
- else
- TestStr = "<your string>"
- end if
- regstring = regstring & "Set Test = regEx.Test(teststring)"
- Response.write "<br><textarea style='background-color:#FFFFCC;' cols=120 rows=7>" & regstring & "</textarea><br>"
- Response.write "Results:<br><textarea style='background-color:#FFFFCC;' name='AllSub' cols=120 rows=1 tabindex=99>regEx.Test(teststring) = " & Test & "</textarea>"
- End if
- Response.write "</form></body></html>"
- End If
- Set regEx=NOTHING
- %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement