473,394 Members | 1,746 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,394 software developers and data experts.

Regular Expression Help

I'm somewhat new to regular expressions and am in need of assistance. I'd
like to match on any OBJECT, EMBED, or APPLET element nested inside an
<HTML> element. Would someone point me in the right direction for creating
such a regular expression or at least point me to the correct news group?

Kindest regards,
Michael
Mar 24 '06 #1
8 1551
Hi Michael,

I'm not that good with Regex, though I do confess to a strong
fascination for them, so I can't answer you outright. I'll work on it,
see if I can come up with something...

The best places to ask questions about Regular Expressions are :

1. There is a Regex group (not hosted by MSNews). It can be reached by
:
http://groups.google.com/group/regex?lnk=li

2. Regexadvice.com and RegexLib.com maintain forums where you can
usually ask questions on Regex Construction.

These are the main Newsgroups that the Regex Gurus monitor... I would
suggest posting there, for maximum response.

It is always useful when trying to construct a Regex, if you can
provide some sample text that you would like to match, and try to be as
specific as possible. For instance, would you like to match only the
OBJECT, EMBED etc. tags or everything between them as well...

Hope this helps,

Regards,

Cerebrus.

Mar 24 '06 #2
Michael,
Cerebrus is right, you might want to ask Reg Ex questions in a more
appropriate place.
That said I'll throw in my 2 cents ;-)
Instead of looking for a preformatted answer you'd be better of
learning how to do this from scratch, if you are serious about using
regular expressions.
Two resources I found very helpful when I started using Regular
Expression were these two:

Microsoft:
http://msdn.microsoft.com/library/de...ting051099.asp
Not that you are (or should be using) VBScript for anything besides old
server side ASP pages, but I found this article helpful since it
provided a very nice synopsis of Regular Expression, it is a handy
reference.

DevGuru:
http://www.devguru.com/Technologies/...ef/regexp.html
I love this site. Its a great quick reference.

So to help you along here is a Javascript example Regular Expression I
use to rip out entire HTML tags and their contents:
function removeTag( strInput, tagName )
{
var re = new RegExp("<"+ tagName +"(.|\n)*</"+ tagName +">", "g");
return strInput.replace(re, "");
}

but this could also be done with Literal Notation (when the expression
will be fixed not variable like in the above example).
(here "tagName" is fixed as "s:Schema"...can you tell now that I'm
working with XML ;-) ):
function removeTag( strInput )
{
return strInput.replace( /<s:Schema([\s\S]*)<\/s:Schema>/ig, "");
}

So just to show you how different to functions can be that do the same
thing!
Hope that gets you started ;-)

Mar 24 '06 #3
Michael Primeaux wrote:
I'm somewhat new to regular expressions and am in need of assistance. I'd
like to match on any OBJECT, EMBED, or APPLET element nested inside an
<HTML> element. Would someone point me in the right direction for creating
such a regular expression or at least point me to the correct news group?


[OoEeAa][BbMmPp][JjBbPp][EeLl][CcDdEe][Tt]?

///Peter
Mar 25 '06 #4
Hi Peter...

Your suggestion, though admittedly unorthodox, does not catch the EMBED
tag, but it can catch EMBEDT...

Just FYI,

Regards,

Cerebrus.

Mar 25 '06 #5
Cerebrus wrote:
Hi Peter...

Your suggestion, though admittedly unorthodox, does not catch the EMBED
tag, but it can catch EMBEDT...


Probably change the ? to *

///Peter
Mar 26 '06 #6
The following expression meets my requirements.

(?i)(((?<!')(?<!")(<\s*EMBED\s*[^>]+src\s*=[^<]+?(?<!/)\s*>[^*]+?<\s*/\s*EMBED\s*>)|(<\s*EMBED\s*[^>]+src\s*=[^/>]+/>))|((?<!')(?<!")((<\s*OBJECT\s*[^>]+classid\s*=\s*["']clsid:[^>]+?\s*(?<!/)\s*>[^*]+?<\s*/\s*OBJECT\s*>)|(<\s*OBJECT\s*[^>]+classid\s*=\s*["']clsid:[^/>]+/>))|((?i)(?<!')(?<!")(<\s*APPLET\s*[^>]+code\s*=[^<]+?(?<!/)\s*>[^*]+?<\s*/\s*APPLET\s*>)|(<\s*APPLET\s*[^>]+code\s*=[^/>]+/>))))

Regards,
Michael

"Michael Primeaux" <mj********@nospam.msn.com> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
I'm somewhat new to regular expressions and am in need of assistance. I'd
like to match on any OBJECT, EMBED, or APPLET element nested inside an
<HTML> element. Would someone point me in the right direction for creating
such a regular expression or at least point me to the correct news group?

Kindest regards,
Michael

Mar 29 '06 #7
Congrats !

It does seem a bit long, but if it works... then great !

Regards,

Cerebrus.

Mar 30 '06 #8
Wow!
....um, it seems you have all simply ignored my post.

Using the function I posted:

function removeTag( strInput, tagName )
{
var re = new RegExp("<"+ tagName +"(.|\n)*</"+ tagName +">", "g");
return strInput.replace(re, ""); //this can be anything you like,
doesn't have to be a replace
}

you can match those tags easily (and it matches anything in the tag or
ON the tag such as attributes):
removeTag( StringToSearch,"EMBED");
removeTag( StringToSearch,"OBJECT");
removeTag( StringToSearch,"APPLET");

The "remove" part of the function is simply what I've done with the
matched item. You can do anything you like with the match. Of course
you didn't state what you were doing, only that you needed to match on
those tags.

What will happen to your regular expression if I added a new attribute
to the tag?
I think if you write expressions this complicated and specific you'll
quickly start to hate Reg Expr. ;-)

But hey I'm only here to help, good luck!

Mar 30 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
10
by: Lee Kuhn | last post by:
I am trying the create a regular expression that will essentially match characters in the middle of a fixed-length string. The string may be any characters, but will always be the same length. In...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
9
by: Pete Davis | last post by:
I'm using regular expressions to extract some data and some links from some web pages. I download the page and then I want to get a list of certain links. For building regular expressions, I use...
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...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
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...
18
by: Lit | last post by:
Hi, I am looking for a Regular expression for a password for my RegExp ValidationControl Requirements are, At least 8 characters long. At least one digit At least one upper case character
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.