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

Regular Expression Help

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
Congrats !

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

Regards,

Cerebrus.

Mar 30 '06 #8

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.