473,471 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

remove the content in between tags

j1c
How can I remove the content in between tags? I have a page that has
several custom tags: <!--tag:1--> Content 1 <!--/tag:1--> <br>
<!--tag:2--> Content 2 <!--/tag:2--> <br> <!--tag:3--> Content 3
<!--/tag:3--> If I only wanted to see the contents of tag 2 for
example, how could I strip out 1 and 3?

Jul 22 '05 #1
14 2099
Its going to have to be a combination of InStr() to get the positions of the
end of the first tag and the start of the second. Then probably just a
couple Left() and Right() calls to recombine.

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"j1c" <ju********@yahoo.ca> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
How can I remove the content in between tags? I have a page that has
several custom tags: <!--tag:1--> Content 1 <!--/tag:1--> <br>
<!--tag:2--> Content 2 <!--/tag:2--> <br> <!--tag:3--> Content 3
<!--/tag:3--> If I only wanted to see the contents of tag 2 for
example, how could I strip out 1 and 3?

Jul 22 '05 #2
j1c
Could you give an example?

Jul 22 '05 #3
"j1c" <ju********@yahoo.ca> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
How can I remove the content in between tags? I have a page that has
several custom tags: <!--tag:1--> Content 1 <!--/tag:1--> <br>
<!--tag:2--> Content 2 <!--/tag:2--> <br> <!--tag:3--> Content 3
<!--/tag:3--> If I only wanted to see the contents of tag 2 for
example, how could I strip out 1 and 3?


Can you change
<!--tag:1--> Content 1 <!--/tag:1-->

to
<span id="tag1"> Content 1 </span>

if so then will the following help? Watch for word-wrap.

<html>
<head>
<title>tags.htm</title>
<script type="text/javascript">
function tags(what) {
document.getElementById("tag"+what).style.visibili ty = "hidden";
}
</script>
</head>
<body>
<span id="tag1"> Content 1 </span>
<br>
<span id="tag2"> Content 2 </span>
<br>
<span id="tag3"> Content 3 </span>
<input type="button" value="Hide 1" onclick="tags(1)">
<input type="button" value="Hide 2" onclick="tags(2)">
<input type="button" value="Hide 3" onclick="tags(3)">
</body>
</html>

Jul 22 '05 #4
Have you tried?
Break it into steps.
1) grab everything to the left of your opening tag.
2) grab everything to the right of your closing tag.
3) recombine.

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"j1c" <ju********@yahoo.ca> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Could you give an example?

Jul 22 '05 #5
j1c
I used a regex to do it, however I need to do a 'reverse' loop? :)

So, if I have 10 section tags, but only want to see 1,5,7 how can I
loop through removing any matches that do not equal 1,5 or 7

Jul 22 '05 #6
ick.... Since you know that they all start and end with < and > you'll have
to find every instance, check it against your list and keep/dump
accordingly. Sounds like a royal pain.... what is it you are having to do? I
mean maybe there is a better way.

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"j1c" <ju********@yahoo.ca> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
I used a regex to do it, however I need to do a 'reverse' loop? :)

So, if I have 10 section tags, but only want to see 1,5,7 how can I
loop through removing any matches that do not equal 1,5 or 7

Jul 22 '05 #7
j1c
;) yeah it is..

I am getting passed a large string of HTML that will be displayed on a
site or in an email. This string has up to 10 openning and closing tags
like:
<!--tag:1--> bla bla bla <!--/tag:1-->

I am also passed a recordset that has a delimitted list of params
(1,5,7)

Those params match tags that are to be displayed. The rest are to be
stripped.

My regex's are a little rusty, but can I not match everything that !=
the params?

This is what I've got on the go now:
Dim strpage
strpage = "a bunch of html..."
Dim sec
sec = Split(sections, ",")
For i = LBound(sec) To UBound(sec)
Set re1 = New RegExp
re1.IgnoreCase = True
re1.Global = False
re1.Pattern = "<!--tag:" & sec(i) & ">(.*)?<!--/tag:" & sec(i) & ">"
Set Matches = re1.Execute(strpage)

strpage = Replace(strpage, Matches.Item(0).SubMatches(0), "")

Next

Jul 22 '05 #8
ick indeed...
Sorry to say I'm no regex master... Maybe one of the others can get you
closer. Sorry I couldnt....
From the sound of it though, there aren't too many options since you dont
control the incoming file format...

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"j1c" <ju********@yahoo.ca> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
;) yeah it is..

I am getting passed a large string of HTML that will be displayed on a
site or in an email. This string has up to 10 openning and closing tags
like:
<!--tag:1--> bla bla bla <!--/tag:1-->

I am also passed a recordset that has a delimitted list of params
(1,5,7)

Those params match tags that are to be displayed. The rest are to be
stripped.

My regex's are a little rusty, but can I not match everything that !=
the params?

This is what I've got on the go now:
Dim strpage
strpage = "a bunch of html..."
Dim sec
sec = Split(sections, ",")
For i = LBound(sec) To UBound(sec)
Set re1 = New RegExp
re1.IgnoreCase = True
re1.Global = False
re1.Pattern = "<!--tag:" & sec(i) & ">(.*)?<!--/tag:" & sec(i) & ">"
Set Matches = re1.Execute(strpage)

strpage = Replace(strpage, Matches.Item(0).SubMatches(0), "")

Next

Jul 22 '05 #9

j1c wrote:
How can I remove the content in between tags? I have a page that has
several custom tags: <!--tag:1--> Content 1 <!--/tag:1--> <br>
<!--tag:2--> Content 2 <!--/tag:2--> <br> <!--tag:3--> Content 3
<!--/tag:3--> If I only wanted to see the contents of tag 2 for
example, how could I strip out 1 and 3?

Load it into frontpage 2003. It has more advanced editing features
such as this.

Jul 22 '05 #10
"j1c" <ju********@yahoo.ca> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
How can I remove the content in between tags? I have a page that has
several custom tags: <!--tag:1--> Content 1 <!--/tag:1--> <br>
<!--tag:2--> Content 2 <!--/tag:2--> <br> <!--tag:3--> Content 3
<!--/tag:3--> If I only wanted to see the contents of tag 2 for
example, how could I strip out 1 and 3?


<%
Dim s, arr, re
s = _
"<!--tag:1-->Content 1<!--/tag:1--><br>" &_
"<!--tag:2-->Content 2<!--/tag:2--><br>" &_
"<!--tag:3-->Content 3<!--/tag:3--><br>" &_
"<!--tag:4-->Content 4<!--/tag:4--><br>" &_
"<!--tag:5-->Content 5<!--/tag:5--><br>" &_
"<!--tag:6-->Content 6<!--/tag:6--><br>" &_
"<!--tag:7-->Content 7<!--/tag:7--><br>" &_
"<!--tag:8-->Content 8<!--/tag:8--><br>" &_
"<!--tag:9-->Content 9<!--/tag:9--><br>" &_
"<!--tag:10-->Content 10<!--/tag:10-->"

arr = Array(1,5,7)

Set re = New RegExp
re.Global = True
re.IgnoreCase = True
re.Pattern = "(<!--tag:(?!(" & Join(arr,"|") &
")-)(\d+)-->).*(<!--/tag:\3-->)"

Response.Write re.Replace(s,"$1$4")
%>
Jul 22 '05 #11

"Chris Hohmann" <no****@thankyou.com> wrote in message
news:eu*************@TK2MSFTNGP14.phx.gbl...
"j1c" <ju********@yahoo.ca> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
How can I remove the content in between tags? I have a page that has
several custom tags: <!--tag:1--> Content 1 <!--/tag:1--> <br>
<!--tag:2--> Content 2 <!--/tag:2--> <br> <!--tag:3--> Content 3
<!--/tag:3--> If I only wanted to see the contents of tag 2 for
example, how could I strip out 1 and 3?


<%
Dim s, arr, re
s = _
"<!--tag:1-->Content 1<!--/tag:1--><br>" &_
"<!--tag:2-->Content 2<!--/tag:2--><br>" &_
"<!--tag:3-->Content 3<!--/tag:3--><br>" &_
"<!--tag:4-->Content 4<!--/tag:4--><br>" &_
"<!--tag:5-->Content 5<!--/tag:5--><br>" &_
"<!--tag:6-->Content 6<!--/tag:6--><br>" &_
"<!--tag:7-->Content 7<!--/tag:7--><br>" &_
"<!--tag:8-->Content 8<!--/tag:8--><br>" &_
"<!--tag:9-->Content 9<!--/tag:9--><br>" &_
"<!--tag:10-->Content 10<!--/tag:10-->"

arr = Array(1,5,7)

Set re = New RegExp
re.Global = True
re.IgnoreCase = True
re.Pattern = "(<!--tag:(?!(" & Join(arr,"|") &
")-)(\d+)-->).*(<!--/tag:\3-->)"

Response.Write re.Replace(s,"$1$4")
%>


You may want to throw in a non-greedy clause if it's possible that tags
would repeat. The new pattern would be

re.Pattern = "(<!--tag:(?!(" & Join(arr,"|") &
")-)(\d+)-->).*?(<!--/tag:\3-->)"

HTH
-Chris Hohmann
Jul 22 '05 #12
j1c
Thanks for the tips - it is working very well.

1 thing though - in the RegEx what would I need to change to allow
either:

<!--tag:01-->content<!--/tag:01-->

OR

<!--tag:01-->
content
<!--/tag:01-->

Jul 22 '05 #13
"j1c" <ju********@yahoo.ca> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Thanks for the tips - it is working very well.

1 thing though - in the RegEx what would I need to change to allow
either:

<!--tag:01-->content<!--/tag:01-->

OR

<!--tag:01-->
content
<!--/tag:01-->


<%
Dim s, arr, re
s = _
"<!--tag:1-->Content 1<!--/tag:1--><br>" &_
"<!--tag:2-->Content 2<!--/tag:2--><br>" &_
"<!--tag:3-->Content 3<!--/tag:3--><br>" &_
"<!--tag:4-->Content 4<!--/tag:4--><br>" &_
"<!--tag:5-->Content 5<!--/tag:5--><br>" &_
"<!--tag:6-->Content 6<!--/tag:6--><br>" &_
"<!--tag:7-->Content 7<!--/tag:7--><br>" &_
"<!--tag:8-->Content 8<!--/tag:8--><br>" &_
"<!--tag:9-->Content 9<!--/tag:9--><br>" &_
"<!--tag:10-->" & vbCRLF & "Content 10" & vbCRLF & "<!--/tag:10-->"

arr = Array(1,5,7)

Set re = New RegExp
re.Global = True
re.IgnoreCase = True
re.MultiLine=True
re.Pattern = "(<!--tag:(?!(" & Join(arr,"|") &
")-)(\d+)-->)(.|\n)*?(<!--/tag:\3-->)"

Response.Write re.Replace(s,"$1$5")
%>
Jul 22 '05 #14
j1c
thanks for the tips guys

Jul 22 '05 #15

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

Similar topics

4
by: Nico Grubert | last post by:
Hello, I want to remove all html tags from a string "content" except <a ....>xxx</a>. My script reads like this: ### import re content = re.sub('<((|\n)*)>', '', content)
1
by: Aaron Fleming | last post by:
How can I remove the content in between tags? I have a page that has several custom tags: <!--tag:1--> Content 1 <!--/tag:1--> <br> <!--tag:2--> Content 2 <!--/tag:2-->
10
by: clintonG | last post by:
Can somebody direct me to documents or source that supports the use of collapsible content that is collapsed by default when the page is loaded? The secondary objective would of course be...
12
by: Oberon | last post by:
I have a large HTML document. It has hundreds of <span>s which have no attributes so these <span>s are redundant. How can I remove these tags automatically? The document also has <span>s with...
1
by: Miguel Dias Moura | last post by:
Hello, I am adding a MetaTag from my .pasx.vb code: Dim metaTag As New HtmlMeta() metaTag.Name = "Title" metaTag.Content = "My Web Site" Page.Header.Controls.Add(metaTag) Later in my code I...
1
by: dave8421 | last post by:
Hi, I'm trying to make sense of the definition for "Rendered Content" in current CR for CSS 2.1 Is rendered content what is displayed on the particular media or device? from the...
0
by: peter pilsl | last post by:
For feeding the content of an xml-file to a search-indexer I need to remove all tags and extract the plaintext out of a xml-file. I use the null-xls-stylesheet <?xml version="1.0"?>...
2
by: Sami | last post by:
How can I get the inner content of a tag with regular expression I couldn't the the opening and closing tags to match properly Input "fjkdjfkdj <div>sadfdf dfdf...
3
by: junkchiu | last post by:
want to remove "content" between two corresponding tags. What's the best way of doing it? I want to remove contents between <SEC-HEADER> and <table> tags. I have different tags, and I want to remove...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.