473,395 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help With Regular Expression

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
2 1806
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Steve | last post by:
Hello, I am writing a script that calls a URL and reads the resulting HTML into a function that strips out everthing and returns ONLY the links, this is so that I can build a link index of various...
5
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL,...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
6
by: JohnSouth | last post by:
Hi I've been using a Regular expression to test for valid email addresses. It looks like: \w+(\w+)*@\w+(\w+)*\.\w+(\w+)* I've now had 2 occassions where it has rejected and email address...
3
by: Joe | last post by:
Hi, I have been using a regular expression that I don’t uite understand to filter the valid email address. My regular expression is as follows: <asp:RegularExpressionValidator...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
3
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular...
6
by: deepak_kamath_n | last post by:
Hello, I am relatively new to the world of regex and require some help in forming a regular expression to achieve the following: I have an input stream similar to: Slot: slot1 Description:...
14
by: Chris | last post by:
I need a pattern that matches a string that has the same number of '(' as ')': findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = Can anybody help me out? Thanks for any help!
3
by: Mr.Steskal | last post by:
Posted: Wed Jul 11, 2007 7:01 am Post subject: Regular Expression Help -------------------------------------------------------------------------------- I need help writing a regular...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.