473,574 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

I have a web site called HintsAndTips.co m. 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.EncodeHT ML 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 2736
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*********@hi ntsandtips.com> wrote in message
news:Od******** *****@TK2MSFTNG P11.phx.gbl...
I have a web site called HintsAndTips.co m. 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.EncodeHT ML 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_da rkfalz.com> wrote in message
news:ex******** ******@TK2MSFTN GP11.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*********@hi ntsandtips.com> wrote in message
news:Od******** *****@TK2MSFTNG P11.phx.gbl...
I have a web site called HintsAndTips.co m. 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.EncodeHT ML 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*********@hi ntsandtips.com> wrote in message
news:OG******** ******@tk2msftn gp13.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_da rkfalz.com> wrote in message
news:ex******** ******@TK2MSFTN GP11.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*********@hi ntsandtips.com> wrote in message
news:Od******** *****@TK2MSFTNG P11.phx.gbl...
I have a web site called HintsAndTips.co m. 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.EncodeHT ML 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_da rkfalz.com> wrote in message
news:eI******** ******@TK2MSFTN GP11.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*********@hi ntsandtips.com> wrote in message
news:OG******** ******@tk2msftn gp13.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_da rkfalz.com> wrote in message
news:ex******** ******@TK2MSFTN GP11.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*********@hi ntsandtips.com> wrote in message
news:Od******** *****@TK2MSFTNG P11.phx.gbl...
> I have a web site called HintsAndTips.co m. 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.EncodeHT ML 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*********@hi ntsandtips.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.c om...
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*********@hi ntsandtips.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.c om...
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.co m> 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
10922
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 from the "normal" left side. How do I do that without coding "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" ? Is there something like...
21
10196
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 rendering of <pre> in a fixed width font. To change that I'd have to specify a proportional font family, thereby falling into the size pitfall that...
37
3938
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 unicode EOL characer, which is 000A. I figured with was 10 in decimal notation, and so tried: line 1 line 2 No go. What was wrong with my thinking...
7
19108
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 the browser. I even replaced all the newlines with <BR/> tags but eventhough I see the tags in my source, I don't get a line break in the output...
9
5536
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 shell pieces like this: <pre><code> #!/bin/sh ftp -i -n ftp.server.com&lt; &lt;EOF user username password epsv4 cd /
10
6564
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 if anyone know the spec for XML case, please let me know. Thanks. Xah
56
3747
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
3921
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 layout is part of the markup. Cheers, Lister
0
7736
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8249
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8107
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5631
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5307
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3748
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2252
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 we have to send another system
1
1352
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1071
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.