473,320 Members | 2,161 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,320 software developers and data experts.

Regex help!

Rob

Hi,
I've written a small VB application that parses an HTML document and
removes code I don't need and re-writes the file. I'm looking for the
regex pattern that will remove the following code:

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
..shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>T1 CRR Online Manual</title>
<style>
<!--

-->
</style>
</head>

...of course the page continues after the </headtag but I want to
remove everything within the head tags including the head tags. This has
to work on any HTML file that I parse so the contents within the head
tags may be different. This is what I've got so far:

pattern = "<head>[.|\s|\n]*<\/head>"
returntext = Regex.Replace(returntext, pattern, "")

...but this doesn't work. Anyone out there with a solution?

Thanks
Rob
*** Sent via Developersdex http://www.developersdex.com ***
May 10 '07 #1
3 1631
On May 10, 1:50 pm, Rob <rob...@hotmail.comwrote:
Hi,
I've written a small VB application that parses an HTML document and
removes code I don't need and re-writes the file. I'm looking for the
regex pattern that will remove the following code:

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>T1 CRR Online Manual</title>
<style>
<!--

-->
</style>
</head>

..of course the page continues after the </headtag but I want to
remove everything within the head tags including the head tags. This has
to work on any HTML file that I parse so the contents within the head
tags may be different. This is what I've got so far:

pattern = "<head>[.|\s|\n]*<\/head>"
returntext = Regex.Replace(returntext, pattern, "")

..but this doesn't work. Anyone out there with a solution?

Thanks
Rob

*** Sent via Developersdexhttp://www.developersdex.com***
How about:

Regex.Replace(returnText, "<head>.*</head>", "",
RegexOptions.Singleline)

Thanks,

Seth Rowe

May 10 '07 #2
Rob
Thanks Seth,

That works...but only with the RegexOptions.SingleLine parameter. I
didn't have that before.

Rob

*** Sent via Developersdex http://www.developersdex.com ***
May 10 '07 #3
On May 10, 2:19 pm, Rob <rob...@hotmail.comwrote:
Thanks Seth,

That works...but only with the RegexOptions.SingleLine parameter. I
didn't have that before.

Rob

*** Sent via Developersdexhttp://www.developersdex.com***
That because the singleline option tells the period to also match the
newline character.

Thanks,

Seth Rowe
May 10 '07 #4

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

Similar topics

6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
7
by: Mike Labosh | last post by:
I have the following System.Text.RegularExpressions.Regex that is supposed to remove this predefined list of garbage characters from contact names that come in on import files : Dim...
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
4
by: Chris | last post by:
Hi Everyone, I am using a regex to check for a string. When all the file contains is my test string the regex returns a match, but when I embed the test string in the middle of a text file a...
7
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
6
by: Phil Barber | last post by:
I am using Regex to validate a file name. I have everything I need except I would like the dot(.) in the filename only to appear once. My question is it possible to allow one instance of character...
1
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
0
by: Support Desk | last post by:
That’s it exactly..thx -----Original Message----- From: Reedick, Andrew Sent: Tuesday, June 03, 2008 9:26 AM To: Support Desk Subject: RE: regex help The regex will now skip anything with...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.