Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Rocky Moore
Guest
 
Posts: n/a
#1: Nov 18 '05
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



Curt_C [MVP]
Guest
 
Posts: n/a
#2: Nov 18 '05

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


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" <gRockyMoore@hintsandtips.com> wrote in message
news:Ody$E6d2DHA.556@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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[/color]
a[color=blue]
> 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[/color]
that[color=blue]
> 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[/color]
now[color=blue]
> 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[/color]
one[color=blue]
> is missing.
>
> Is this even possible? Do I need to parse the text line-by-line or maybe[/color]
it[color=blue]
> is just something really simple I am overlooking?
>
> Any help appreciated!
> --
> Rocky Moore
> www.HintsAndTips.com
>
>[/color]


Rocky Moore
Guest
 
Posts: n/a
#3: Nov 18 '05

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


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:exuzm9d2DHA.1188@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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" <gRockyMoore@hintsandtips.com> wrote in message
> news:Ody$E6d2DHA.556@TK2MSFTNGP11.phx.gbl...[color=green]
> > I have a web site called HintsAndTips.com. On this site people post[/color][/color]
tips[color=blue][color=green]
> > using a very simply webform with a multi line TextBox for inputing the[/color][/color]
tip[color=blue][color=green]
> > text. This text is encode to HTML so that no tags will remain making[/color][/color]
the[color=blue][color=green]
> > 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[/color][/color]
with[color=blue]
> a[color=green]
> > pre tag so that the lines do not wrap, but that it does not spread[/color][/color]
beyond[color=blue][color=green]
> > the width of the content area of the tip. As an example, here is a tip[/color]
> that[color=green]
> > 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[/color][/color]
and[color=blue][color=green]
> > 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[/color]
> now[color=green]
> > 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[/color]
> one[color=green]
> > is missing.
> >
> > Is this even possible? Do I need to parse the text line-by-line or[/color][/color]
maybe[color=blue]
> it[color=green]
> > is just something really simple I am overlooking?
> >
> > Any help appreciated!
> > --
> > Rocky Moore
> > www.HintsAndTips.com
> >
> >[/color]
>
>[/color]


Curt_C [MVP]
Guest
 
Posts: n/a
#4: Nov 18 '05

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


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" <gRockyMoore@hintsandtips.com> wrote in message
news:OGYPmIe2DHA.3224@tk2msftngp13.phx.gbl...[color=blue]
> 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:exuzm9d2DHA.1188@TK2MSFTNGP11.phx.gbl...[color=green]
> > 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" <gRockyMoore@hintsandtips.com> wrote in message
> > news:Ody$E6d2DHA.556@TK2MSFTNGP11.phx.gbl...[color=darkred]
> > > I have a web site called HintsAndTips.com. On this site people post[/color][/color]
> tips[color=green][color=darkred]
> > > using a very simply webform with a multi line TextBox for inputing the[/color][/color]
> tip[color=green][color=darkred]
> > > text. This text is encode to HTML so that no tags will remain making[/color][/color]
> the[color=green][color=darkred]
> > > 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[/color][/color][/color]
to[color=blue][color=green][color=darkred]
> > > specify an area of the tip that will be blocked into a scrollable div[/color][/color]
> with[color=green]
> > a[color=darkred]
> > > pre tag so that the lines do not wrap, but that it does not spread[/color][/color]
> beyond[color=green][color=darkred]
> > > the width of the content area of the tip. As an example, here is a[/color][/color][/color]
tip[color=blue][color=green]
> > that[color=darkred]
> > > 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[/color][/color]
> and[color=green][color=darkred]
> > > 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[/color][/color][/color]
(but[color=blue][color=green]
> > now[color=darkred]
> > > 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[/color][/color][/color]
do[color=blue][color=green][color=darkred]
> > > that if the <pre></pre> tags are balanced so that it will do nothing[/color][/color][/color]
if[color=blue][color=green]
> > one[color=darkred]
> > > is missing.
> > >
> > > Is this even possible? Do I need to parse the text line-by-line or[/color][/color]
> maybe[color=green]
> > it[color=darkred]
> > > is just something really simple I am overlooking?
> > >
> > > Any help appreciated!
> > > --
> > > Rocky Moore
> > > www.HintsAndTips.com
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Rocky Moore
Guest
 
Posts: n/a
#5: Nov 18 '05

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


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:eIrNZee2DHA.2308@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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" <gRockyMoore@hintsandtips.com> wrote in message
> news:OGYPmIe2DHA.3224@tk2msftngp13.phx.gbl...[color=green]
> > 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:exuzm9d2DHA.1188@TK2MSFTNGP11.phx.gbl...[color=darkred]
> > > 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" <gRockyMoore@hintsandtips.com> wrote in message
> > > news:Ody$E6d2DHA.556@TK2MSFTNGP11.phx.gbl...
> > > > I have a web site called HintsAndTips.com. On this site people post[/color]
> > tips[color=darkred]
> > > > using a very simply webform with a multi line TextBox for inputing[/color][/color][/color]
the[color=blue][color=green]
> > tip[color=darkred]
> > > > text. This text is encode to HTML so that no tags will remain[/color][/color][/color]
making[color=blue][color=green]
> > the[color=darkred]
> > > > 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[/color][/color]
> to[color=green][color=darkred]
> > > > specify an area of the tip that will be blocked into a scrollable[/color][/color][/color]
div[color=blue][color=green]
> > with[color=darkred]
> > > a
> > > > pre tag so that the lines do not wrap, but that it does not spread[/color]
> > beyond[color=darkred]
> > > > the width of the content area of the tip. As an example, here is a[/color][/color]
> tip[color=green][color=darkred]
> > > 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[/color][/color][/color]
scroll[color=blue][color=green]
> > and[color=darkred]
> > > > not break the formatting of the page. But as you can see there are[/color][/color][/color]
no[color=blue][color=green][color=darkred]
> > > > linefeeds in that special section which do exist in the tip itself[/color][/color]
> (but[color=green][color=darkred]
> > > now
> > > > as <BR>s).
> > > >
> > > > So, I need to build a RegEx expression that will replace all[/color][/color][/color]
linefeeds[color=blue][color=green][color=darkred]
> > > > except between <pre></pre> tags. Would also be nice if it would[/color][/color][/color]
only[color=blue]
> do[color=green][color=darkred]
> > > > that if the <pre></pre> tags are balanced so that it will do nothing[/color][/color]
> if[color=green][color=darkred]
> > > one
> > > > is missing.
> > > >
> > > > Is this even possible? Do I need to parse the text line-by-line or[/color]
> > maybe[color=darkred]
> > > it
> > > > is just something really simple I am overlooking?
> > > >
> > > > Any help appreciated!
> > > > --
> > > > Rocky Moore
> > > > www.HintsAndTips.com
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Dan Brussee
Guest
 
Posts: n/a
#6: Nov 18 '05

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


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"
<gRockyMoore@hintsandtips.com> wrote:
[color=blue]
>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.[/color]

Rocky Moore
Guest
 
Posts: n/a
#7: Nov 18 '05

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


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" <dbrussee@nc.rr.com> wrote in message
news:1ba800d3m7g4a43kq8hlpk2kkphhmj2fu8@4ax.com...[color=blue]
> 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"
> <gRockyMoore@hintsandtips.com> wrote:
>[color=green]
> >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[/color][/color]
special[color=blue][color=green]
> >tag (which is replaced with a <pre> tags) Simple replaces will replace[/color][/color]
all[color=blue][color=green]
> >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.[/color]
>[/color]


mikeb
Guest
 
Posts: n/a
#8: Nov 18 '05

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


Rocky Moore wrote:[color=blue]
> 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 :([/color]

Post the RegEx you tried - maybe we can get it to work.
[color=blue]
>
> Thanks for the post!
>
> --
> Rocky Moore
> www.HintsAndTips.com
>
>
> "Dan Brussee" <dbrussee@nc.rr.com> wrote in message
> news:1ba800d3m7g4a43kq8hlpk2kkphhmj2fu8@4ax.com...
>[color=green]
>>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"
>><gRockyMoore@hintsandtips.com> wrote:
>>
>>[color=darkred]
>>>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[/color][/color]
>
> special
>[color=green][color=darkred]
>>>tag (which is replaced with a <pre> tags) Simple replaces will replace[/color][/color]
>
> all
>[color=green][color=darkred]
>>>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.[/color]
>>[/color]
>
>[/color]


--
mikeb
Closed Thread