By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,069 Members | 1,716 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,069 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.