Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Regular Expressions
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Regular Expressions

 Post Reply Post Reply Page  123 4>
Author
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Topic: Regular Expressions
    Posted: 03 November 2003 at 3:02am

Basically i want to strip out all javascript. But ive never used regular expressions in asp.net so has anyon egot any good examples or tutorials?

Thanks, Mart.

Back to Top
Bluefrog View Drop Down
Senior Member
Senior Member


Joined: 23 October 2002
Location: Korea, South
Status: Offline
Points: 1701
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bluefrog Quote  Post ReplyReply Direct Link To This Post Posted: 03 November 2003 at 8:26am

Ah... how timely...

I'm in the middle of writing a VB.NET application and the following function is to strip markup. (The app is for doing regular expressions a bit better than the others I've seen. So far it's NOT  . I'll get it there though.)

I'm not quite done, but I would REALLY like to get a couple beta testers for it if anyone is interested. Actually, I was going to post in a few days for beta testers... It requires the .NET framework.

Hopefully this can at least point you in the right direction.

    Private Function removeMarkup(ByVal theBox) As Boolean
        Dim strMarkUp1 As String
        Dim strMarkUp2 As String
        Dim strMarkUp3 As String
        Dim strMarkUp8 As String

        strMarkUp1 = "(<script[^>]*>[\w|\t|\r|\W]*</script>)"
        strMarkUp2 = "(<style[^>]*>[\w|\t|\r|\W]*</style>)"
        strMarkUp3 = "(<object[^>]*>[\w|\t|\r|\W]*</object>)"

        strMarkUp8 = "(<[^<]+>)"

        Try

             ' need to set the multiline option
             Dim rmvOpts As New RegexOptions()

             rmvOpts = RegexOptions.Singleline
             rmvOpts = rmvOpts Or RegexOptions.Multiline
             rmvOpts = rmvOpts Or RegexOptions.IgnoreCase

             theBox.text = Regex.Replace(theBox.text, strMarkUp1, " " & vbCrLf, rmvOpts)
             theBox.text = Regex.Replace(theBox.text, strMarkUp2, " " & vbCrLf, rmvOpts)
             theBox.text = Regex.Replace(theBox.text, strMarkUp3, " " & vbCrLf, rmvOpts)

             theBox.text = Regex.Replace(theBox.text, strMarkUp8, " ", rmvOpts)

        Catch exp As Exception
             MsgBox("We encountered and error: " & exp.Message, MsgBoxStyle.Critical, Me.Text)
        End Try

    End Function

 

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 03 November 2003 at 9:38am

Thanks alot thats helped me. I wouldnt mind beta testing for you.

Thanks, Mart.

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 03 November 2003 at 9:49am

Mart, i am going to take a guess that you are going to "AllowHTMLMode" on FreeTextBox for whatever this is for...

keep in mind that you also need to look out for random closing tags like </tr> and </table> in which a member could totally hork the outputted HTML....

i'd suggest not ever ever alllowing HTML entry unless you (1) trust them and (2) they know what the hell they are doing

besides, that RegEx shown above has holes in it..... look at -borg-'s replace code in the forum code for this to see more extensive removal of script kiddies

Contribute to the working anarchy we fondly call the Internet
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 03 November 2003 at 10:05am

I think it is better to just replace the < and > with &lt; and &gt;.

This way ALL the code entered in the textbox will not be visible for the server, and will show up just like in the [ code ] tags at WWF I guess.

Unless you REALLY want the user to put HTML code in it. BTW, the framework has a feature for this, which you can set at the top of the page (in the header) like this:

<%@ validateRequest=true %>



Edited by Diep-Vriezer
Gone..
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 03 November 2003 at 10:08am

Im keeping AllowHTMLMode False, but this morning i managed to insert a javascript by copy and pasting it into design mode. and its for a forum im writing in asp.net so i have to trust them I will look at the replace functions then.

Thanks, Mart.

Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 03 November 2003 at 10:09am

R U sure?

EDIT: What a useless question...



Edited by Diep-Vriezer
Gone..
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 03 November 2003 at 10:09am
<@ AutoEventWireup="false" %> what does that do?
Back to Top
 Post Reply Post Reply Page  123 4>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.