Using Regular Expressions

G

Guest

I need some help.

This regular expression strips out html tags "<>"
/*Strips the HTML tags from strHTML */
Regex objStripHTML = new Regex("<(.|\n)+?>");

How would I construct a Regular expression to strip out one this code:
<STYLE type='text/css' MEDIA='print'>.MSGLINE {display:none;}
</STYLE>

Thanks

Mike
 
M

Matthias Kwiedor

I need some help.

This regular expression strips out html tags "<>"
/*Strips the HTML tags from strHTML */
Regex objStripHTML = new Regex("<(.|\n)+?>");

How would I construct a Regular expression to strip out one this code:
<STYLE type='text/css' MEDIA='print'>.MSGLINE {display:none;}
</STYLE>

Thanks

Mike

<\s*style\s+.*?<\s*/style\s*> and set RegexOptions to Ignore Casesensitive


Matt
 
G

Guest

Matthias:

Many, many thanks but I don't understand the syntax!!!
<\s*style\s+.*?<\s*/style\s*>

Can you break this down for me in english?

Also, I did not find a property to ignore case. Can you advise

Mike

----- Matthias Kwiedor wrote: -----

I need some help.
/*Strips the HTML tags from strHTML */


Matt
 
M

Matthias Kwiedor

Hi Mike,

here the detail Syntax

"<" = HTML Tag open

"\s*" = \s means Whitespace and * means no one, one or more, that means
it finds <style, < style, < style ...

"\s+" = one or more Whitespace (+ Syntax) (<style ... = ok , <style ...
= ok, <style... = false)

..*? = To next character which match after the ? ("hello you" and e.*?o
matches ll)

"<\s*style\s*>" = end tag of </style> but with whitespace check, so it
can be < /style>, </style >, < /style >

Regex m1 = Regex.Match(strSource, @"<REGEX>", RegexOptions.IgnoreCase

This means it find for example as regex = h(.*?)o in HELLO the ELLO in
m1.Groups[1].Value.ToString(), but if you have not set the IgnoreCase it
finds nothing, because you need H(.*?)O ... Regex is CaseSensitive until
you say them this.

Hope this helps...

There are a lot of things about Regex. If you are intersted in this
install Perl, because it has one of the strongest Regex Implementation.
And you find alot of sources for regex and perl at google


Matthias
 
G

Guest

Dear Matthias

Many thanks for your assistance. I really appreciate you taking the time to assist me. I'm now on my way, thanks to you

Regard

Mik


----- Matthias Kwiedor wrote: ----

Hi Mike

here the detail Synta

"<" = HTML Tag open

"\s*" = \s means Whitespace and * means no one, one or more, that means
it finds <style, < style, < style ..

"\s+" = one or more Whitespace (+ Syntax) (<style ... = ok , <style ...
= ok, <style... = false

..*? = To next character which match after the ? ("hello you" and e.*?o
matches ll

"<\s*style\s*>" = end tag of </style> but with whitespace check, so it
can be < /style>, </style >, < /style >

Regex m1 = Regex.Match(strSource, @"<REGEX>", RegexOptions.IgnoreCase

This means it find for example as regex = h(.*?)o in HELLO the ELLO in
m1.Groups[1].Value.ToString(), but if you have not set the IgnoreCase it
finds nothing, because you need H(.*?)O ... Regex is CaseSensitive until
you say them this

Hope this helps..

There are a lot of things about Regex. If you are intersted in this
install Perl, because it has one of the strongest Regex Implementation.
And you find alot of sources for regex and perl at googl


Matthia
 
G

Guest

Eric

Thanks for the tip. But we are still on Framework 1.0.

The tool requires 1.1 framework which I can't install becuase of issue with CMS 2002
do you know if their is a version that will work with 1.0 framework

Thank

Mik

----- Eric Gunnerson [MS] wrote: ----

Mike

You might want to try the Regex workbench at

http://www.gotdotnet.com/Community/...ampleGuid=C712F2DF-B026-4D58-8961-4EE2729D732

If you type in a regex, it can tell you what it means

--
Eric Gunnerso

Visit the C# product team at http://www.csharp.ne
Eric's blog is at http://weblogs.asp.net/ericgu

This posting is provided "AS IS" with no warranties, and confers no rights
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top