By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

Help With Regular Expression

P: n/a
Hello guys, I'm trying to learn about regular expressions. I need to
be able to use an RE that can evaluate for STRINGS (or specific
sequences of characters), not just occurances of characters.
Everything I have read thus far involves checking only for the
presence or absence of characters. Can anyone provide an RE that will
correctly evaluate a string to see if it contains other strings,
specifically these (omit the quotes)..."<script>", "<object>",
"<html>", "<head>", "<body>" and/or "<form>".

Oct 22 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Oct 22, 9:48 pm, Joey <joey.pow...@topscene.comwrote:
Hello guys, I'm trying to learn about regular expressions. I need to
be able to use an RE that can evaluate for STRINGS (or specific
sequences of characters), not just occurances of characters.
Everything I have read thus far involves checking only for the
presence or absence of characters. Can anyone provide an RE that will
correctly evaluate a string to see if it contains other strings,
specifically these (omit the quotes)..."<script>", "<object>",
"<html>", "<head>", "<body>" and/or "<form>".
Joey,

if you have a string like this

"hello blabla some text <scriptagain <objectagain over"

Then you can find if it contains "<script>" by using

"\<script\>"

If you need to find if it contains more than one string, for example
"<script>" and "<object>", you should either use

"\<script\>|\<object\>" <--- it means "<script>" OR"<object>"

with an additional check in the code to see if both of them are there,
or you can do

"\<script\>(.|\n)*?\<object\>"

which means "look for <scriptand for <objectwith any number of
characters, or line brakes in between"

Oct 22 '07 #2

P: n/a
On Oct 22, 4:38 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On Oct 22, 9:48 pm, Joey <joey.pow...@topscene.comwrote:
Hello guys, I'm trying to learn about regular expressions. I need to
be able to use an RE that can evaluate for STRINGS (or specific
sequences of characters), not just occurances of characters.
Everything I have read thus far involves checking only for the
presence or absence of characters. Can anyone provide an RE that will
correctly evaluate a string to see if it contains other strings,
specifically these (omit the quotes)..."<script>", "<object>",
"<html>", "<head>", "<body>" and/or "<form>".

Joey,

if you have a string like this

"hello blabla some text <scriptagain <objectagain over"

Then you can find if it contains "<script>" by using

"\<script\>"

If you need to find if it contains more than one string, for example
"<script>" and "<object>", you should either use

"\<script\>|\<object\>" <--- it means "<script>" OR"<object>"

with an additional check in the code to see if both of them are there,
or you can do

"\<script\>(.|\n)*?\<object\>"

which means "look for <scriptand for <objectwith any number of
characters, or line brakes in between"
I have a webpage that has a textbox to take input as text, html tags
and css. Then right under is a second one that will, on postback,
display/markup the entered data from the first textbox. I used a
regular expression validator and entered \<script\as the validation
expression.

When I enter data, including a <scripttag and then click the
"Preview" button, the page posts back (why?) and then two javascript
errors occur...

Line: 168
Char: 1
Error: Syntax error
Code: 0
[page]

Line: 224
Char: 1
Error: 'ctl00_conMain_vsmEnter' is null or not an object
Code: 0
[page]

In the js errors above, 'vsmEnter' is what is (supposed to be?)
rendered off of my validation summary server control.

In any case, I shouldn't be getting these errors, because the regular
expression validator should be blocking the postback when I enter
<scriptin the first textbox. The only thing I can think of is I must
have the wrong validation expression entered - \<script\is not
working. I just need a validation expression that will allow for me to
detect if any of the following is entered in the first
textbox...<script<object<html<head<body<form>

Does anyone have any ideas about what else I can try?

Oct 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.