Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / March 2006

Tip: Looking for answers? Try searching our database.

Regular Expression Help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Primeaux - 24 Mar 2006 04:53 GMT
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
Cerebrus - 24 Mar 2006 08:44 GMT
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.
KillerJ - 24 Mar 2006 14:43 GMT
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/default.asp?url=/library/en-us/dnclinic/html/s
cripting051099.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/ecmascript/quickref/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 ;-)
Peter Flynn - 25 Mar 2006 13:25 GMT
> 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
Cerebrus - 25 Mar 2006 14:22 GMT
Hi Peter...

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

Just FYI,

Regards,

Cerebrus.
Peter Flynn - 26 Mar 2006 02:02 GMT
> Hi Peter...
>
> Your suggestion, though admittedly unorthodox, does not catch the EMBED
> tag, but it can catch EMBEDT...

Probably change the ? to *

///Peter
Michael Primeaux - 29 Mar 2006 18:27 GMT
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

> 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
[quoted text clipped - 3 lines]
> Kindest regards,
> Michael
Cerebrus - 30 Mar 2006 14:05 GMT
Congrats !

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

Regards,

Cerebrus.
KillerJ - 30 Mar 2006 14:43 GMT
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!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.