473,378 Members | 1,162 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,378 software developers and data experts.

RegEx for changing linefeeds to <BR> except between <PRE></PRE> tags?

I have a web site called HintsAndTips.com. On this site people post tips
using a very simply webform with a multi line TextBox for inputing the tip
text. This text is encode to HTML so that no tags will remain making the
page safe (I have to convert the linefeeds to <BR>s because the
Server.EncodeHTML does not do that it seems).

The problem is that users can use a special tag when editing the top to
specify an area of the tip that will be blocked into a scrollable div with a
pre tag so that the lines do not wrap, but that it does not spread beyond
the width of the content area of the tip. As an example, here is a tip that
uses this tag which is replaced with the div and pre tags as needed:

http://hintsandtips.com/hat.aspx?P=S...=31&F=100&T=10

If the text in that special area is wider than the page it will scroll and
not break the formatting of the page. But as you can see there are no
linefeeds in that special section which do exist in the tip itself (but now
as <BR>s).

So, I need to build a RegEx expression that will replace all linefeeds
except between <pre></pre> tags. Would also be nice if it would only do
that if the <pre></pre> tags are balanced so that it will do nothing if one
is missing.

Is this even possible? Do I need to parse the text line-by-line or maybe it
is just something really simple I am overlooking?

Any help appreciated!
--
Rocky Moore
www.HintsAndTips.com
Nov 18 '05 #1
7 2711
1) Replace the BR's
2) Replace the "special" tags with something like "||"
3) Encode
4) Replace the "||" back with the "<pre></pre>" tags
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Rocky Moore" <gR*********@hintsandtips.com> wrote in message
news:Od*************@TK2MSFTNGP11.phx.gbl...
I have a web site called HintsAndTips.com. On this site people post tips
using a very simply webform with a multi line TextBox for inputing the tip
text. This text is encode to HTML so that no tags will remain making the
page safe (I have to convert the linefeeds to <BR>s because the
Server.EncodeHTML does not do that it seems).

The problem is that users can use a special tag when editing the top to
specify an area of the tip that will be blocked into a scrollable div with a pre tag so that the lines do not wrap, but that it does not spread beyond
the width of the content area of the tip. As an example, here is a tip that uses this tag which is replaced with the div and pre tags as needed:

http://hintsandtips.com/hat.aspx?P=S...=31&F=100&T=10

If the text in that special area is wider than the page it will scroll and
not break the formatting of the page. But as you can see there are no
linefeeds in that special section which do exist in the tip itself (but now as <BR>s).

So, I need to build a RegEx expression that will replace all linefeeds
except between <pre></pre> tags. Would also be nice if it would only do
that if the <pre></pre> tags are balanced so that it will do nothing if one is missing.

Is this even possible? Do I need to parse the text line-by-line or maybe it is just something really simple I am overlooking?

Any help appreciated!
--
Rocky Moore
www.HintsAndTips.com

Nov 18 '05 #2
Confused, how does that maintain the linefeeds between the "<pre></pre>"
tags?

I do not have a problem with the special tag itself being changed in the
encode process since I simple replace the "&lt;FIXED&gt;" string ;)

--
Rocky Moore
www.HintsAndTips.com

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:ex**************@TK2MSFTNGP11.phx.gbl...
1) Replace the BR's
2) Replace the "special" tags with something like "||"
3) Encode
4) Replace the "||" back with the "<pre></pre>" tags
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Rocky Moore" <gR*********@hintsandtips.com> wrote in message
news:Od*************@TK2MSFTNGP11.phx.gbl...
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no tags will remain making the page safe (I have to convert the linefeeds to <BR>s because the
Server.EncodeHTML does not do that it seems).

The problem is that users can use a special tag when editing the top to
specify an area of the tip that will be blocked into a scrollable div with
a
pre tag so that the lines do not wrap, but that it does not spread
beyond the width of the content area of the tip. As an example, here is a tip

that
uses this tag which is replaced with the div and pre tags as needed:

http://hintsandtips.com/hat.aspx?P=S...=31&F=100&T=10

If the text in that special area is wider than the page it will scroll and not break the formatting of the page. But as you can see there are no
linefeeds in that special section which do exist in the tip itself (but

now
as <BR>s).

So, I need to build a RegEx expression that will replace all linefeeds
except between <pre></pre> tags. Would also be nice if it would only do
that if the <pre></pre> tags are balanced so that it will do nothing if

one
is missing.

Is this even possible? Do I need to parse the text line-by-line or

maybe it
is just something really simple I am overlooking?

Any help appreciated!
--
Rocky Moore
www.HintsAndTips.com


Nov 18 '05 #3
I had 1 & 2 backwards.... but you already had that taken care of....
I guess if you already can change these back then what's the issue?

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Rocky Moore" <gR*********@hintsandtips.com> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
Confused, how does that maintain the linefeeds between the "<pre></pre>"
tags?

I do not have a problem with the special tag itself being changed in the
encode process since I simple replace the "&lt;FIXED&gt;" string ;)

--
Rocky Moore
www.HintsAndTips.com

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:ex**************@TK2MSFTNGP11.phx.gbl...
1) Replace the BR's
2) Replace the "special" tags with something like "||"
3) Encode
4) Replace the "||" back with the "<pre></pre>" tags
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Rocky Moore" <gR*********@hintsandtips.com> wrote in message
news:Od*************@TK2MSFTNGP11.phx.gbl...
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no tags will remain making the page safe (I have to convert the linefeeds to <BR>s because the
Server.EncodeHTML does not do that it seems).

The problem is that users can use a special tag when editing the top to specify an area of the tip that will be blocked into a scrollable div with
a
pre tag so that the lines do not wrap, but that it does not spread beyond the width of the content area of the tip. As an example, here is a tip that
uses this tag which is replaced with the div and pre tags as needed:

http://hintsandtips.com/hat.aspx?P=S...=31&F=100&T=10

If the text in that special area is wider than the page it will scroll and not break the formatting of the page. But as you can see there are no
linefeeds in that special section which do exist in the tip itself
(but now
as <BR>s).

So, I need to build a RegEx expression that will replace all linefeeds
except between <pre></pre> tags. Would also be nice if it would only
do that if the <pre></pre> tags are balanced so that it will do nothing

if one
is missing.

Is this even possible? Do I need to parse the text line-by-line or

maybe
it
is just something really simple I am overlooking?

Any help appreciated!
--
Rocky Moore
www.HintsAndTips.com



Nov 18 '05 #4
The issue (and the focus of the post) is how to limit the changes of the
<BR> between the "<pre></pre>" tags as the subject line says ;)

I need to change all the linefeeds to <BR>'s unless it is between my special
tag (which is replaced with a <pre> tags) Simple replaces will replace all
of them. If a tip has one or more of the special sections, those sections
have to be excluded in the replacing of the linefeeds.

--
Rocky Moore
www.HintsAndTips.com
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
I had 1 & 2 backwards.... but you already had that taken care of....
I guess if you already can change these back then what's the issue?

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Rocky Moore" <gR*********@hintsandtips.com> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
Confused, how does that maintain the linefeeds between the "<pre></pre>"
tags?

I do not have a problem with the special tag itself being changed in the
encode process since I simple replace the "&lt;FIXED&gt;" string ;)

--
Rocky Moore
www.HintsAndTips.com

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:ex**************@TK2MSFTNGP11.phx.gbl...
1) Replace the BR's
2) Replace the "special" tags with something like "||"
3) Encode
4) Replace the "||" back with the "<pre></pre>" tags
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Rocky Moore" <gR*********@hintsandtips.com> wrote in message
news:Od*************@TK2MSFTNGP11.phx.gbl...
> I have a web site called HintsAndTips.com. On this site people post tips
> using a very simply webform with a multi line TextBox for inputing the
tip
> text. This text is encode to HTML so that no tags will remain
making
the
> page safe (I have to convert the linefeeds to <BR>s because the
> Server.EncodeHTML does not do that it seems).
>
> The problem is that users can use a special tag when editing the top to > specify an area of the tip that will be blocked into a scrollable
div with
a
> pre tag so that the lines do not wrap, but that it does not spread

beyond
> the width of the content area of the tip. As an example, here is a tip that
> uses this tag which is replaced with the div and pre tags as needed:
>
> http://hintsandtips.com/hat.aspx?P=S...=31&F=100&T=10
>
> If the text in that special area is wider than the page it will
scroll and
> not break the formatting of the page. But as you can see there are

no > linefeeds in that special section which do exist in the tip itself

(but now
> as <BR>s).
>
> So, I need to build a RegEx expression that will replace all linefeeds > except between <pre></pre> tags. Would also be nice if it would
only do > that if the <pre></pre> tags are balanced so that it will do nothing if one
> is missing.
>
> Is this even possible? Do I need to parse the text line-by-line or

maybe
it
> is just something really simple I am overlooking?
>
> Any help appreciated!
> --
> Rocky Moore
> www.HintsAndTips.com
>
>



Nov 18 '05 #5
Thinking out loud... umm... online... whatever...

Find the text between <pre> and </pre> and store it in a var. Then
replace all occurnaces of linefeeds with <BR>. Then replace the
<pre></pre> (now empty) with the value stored.
On Tue, 13 Jan 2004 07:30:13 -0800, "Rocky Moore"
<gR*********@hintsandtips.com> wrote:
The issue (and the focus of the post) is how to limit the changes of the
<BR> between the "<pre></pre>" tags as the subject line says ;)

I need to change all the linefeeds to <BR>'s unless it is between my special
tag (which is replaced with a <pre> tags) Simple replaces will replace all
of them. If a tip has one or more of the special sections, those sections
have to be excluded in the replacing of the linefeeds.


Nov 18 '05 #6
Yeah, would still be a lot of overhead since there can be multiple tag
sections. You would have to pull all the tag sections and then after you
are done, replace them.

It really seems like a simple task for RegEx, but after quite a bit of
searching on the net, I have yet to find anything close. I found a RegEx
for vb that was supposed to replace the linefeeds except in <pre> tag blocks
but it didn't work with .NET :(

Thanks for the post!

--
Rocky Moore
www.HintsAndTips.com
"Dan Brussee" <db******@nc.rr.com> wrote in message
news:1b********************************@4ax.com...
Thinking out loud... umm... online... whatever...

Find the text between <pre> and </pre> and store it in a var. Then
replace all occurnaces of linefeeds with <BR>. Then replace the
<pre></pre> (now empty) with the value stored.
On Tue, 13 Jan 2004 07:30:13 -0800, "Rocky Moore"
<gR*********@hintsandtips.com> wrote:
The issue (and the focus of the post) is how to limit the changes of the
<BR> between the "<pre></pre>" tags as the subject line says ;)

I need to change all the linefeeds to <BR>'s unless it is between my specialtag (which is replaced with a <pre> tags) Simple replaces will replace allof them. If a tip has one or more of the special sections, those sections
have to be excluded in the replacing of the linefeeds.

Nov 18 '05 #7
Rocky Moore wrote:
Yeah, would still be a lot of overhead since there can be multiple tag
sections. You would have to pull all the tag sections and then after you
are done, replace them.

It really seems like a simple task for RegEx, but after quite a bit of
searching on the net, I have yet to find anything close. I found a RegEx
for vb that was supposed to replace the linefeeds except in <pre> tag blocks
but it didn't work with .NET :(
Post the RegEx you tried - maybe we can get it to work.

Thanks for the post!

--
Rocky Moore
www.HintsAndTips.com
"Dan Brussee" <db******@nc.rr.com> wrote in message
news:1b********************************@4ax.com...
Thinking out loud... umm... online... whatever...

Find the text between <pre> and </pre> and store it in a var. Then
replace all occurnaces of linefeeds with <BR>. Then replace the
<pre></pre> (now empty) with the value stored.
On Tue, 13 Jan 2004 07:30:13 -0800, "Rocky Moore"
<gR*********@hintsandtips.com> wrote:

The issue (and the focus of the post) is how to limit the changes of the
<BR> between the "<pre></pre>" tags as the subject line says ;)

I need to change all the linefeeds to <BR>'s unless it is between my
special
tag (which is replaced with a <pre> tags) Simple replaces will replace
all
of them. If a tip has one or more of the special sections, those sections
have to be excluded in the replacing of the linefeeds.


--
mikeb
Nov 18 '05 #8

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

Similar topics

21
by: Wladimir Borsov | last post by:
Assume I want to publish a longer article on a web page. One of the paragraphs I want to display with an indent. Read: All text lines of this paragraph should be displayed with (let's say 8) blanks...
21
by: Headless | last post by:
I've marked up song lyrics with the <pre> tag because it seems the most appropriate type of markup for the type of data. This results in inefficient use of horizontal space due to UA's default...
37
by: Haines Brown | last post by:
I understand that <br /> is marginal in CSS, and so am looking for a substitute for the EOL character. I've failed in both approaches and seek advice. The first thing I tried was to use the...
7
by: noor.rahman | last post by:
I have an XML file that stores data from an HTML form. I use XSL to display the data in HTML format. The data may have newline characters. However, XSL is not displaying the newlines properly in...
9
by: Eric Lindsay | last post by:
I can't figure how to best display little snippets of shell script using <pre>. I just got around to organising to bulk validate some of my web pages, and one of the problems occurs with Bash...
10
by: Xah Lee | last post by:
there's a HTML odditity. That is, line break will be ignored inside <preif the adjacent lines are tags. see the source code and description here: http://xahlee.org/js/linebreak_after_tag.html...
56
by: Ed Jay | last post by:
I note in an Eric Meyers book that he expresses one goal of using CSS is to eliminate all <brtags. Why? -- Ed Jay (remove 'M' to respond by email)
13
by: lister | last post by:
If I want to move something to a new line, should I be using <br/>, or is there a way of doing it in CSS? I was just thinking if it was possible in CSS then it would be better as otherwise the...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.