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

Discussion in 'ASP .Net' started by Rocky Moore, Jan 13, 2004.

  1. Rocky Moore

    Rocky Moore Guest

    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=ShowTip&C=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
     
    Rocky Moore, Jan 13, 2004
    #1
    1. Advertising

  2. Rocky Moore

    Curt_C [MVP] Guest

    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" <> wrote in message
    news:Ody$...
    > 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=ShowTip&C=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], Jan 13, 2004
    #2
    1. Advertising

  3. Rocky Moore

    Rocky Moore Guest

    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:...
    > 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" <> wrote in message
    > news:Ody$...
    > > 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=ShowTip&C=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
    > >
    > >

    >
    >
     
    Rocky Moore, Jan 13, 2004
    #3
  4. Rocky Moore

    Curt_C [MVP] Guest

    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" <> wrote in message
    news:...
    > 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:...
    > > 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" <> wrote in message
    > > news:Ody$...
    > > > 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=ShowTip&C=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], Jan 13, 2004
    #4
  5. Rocky Moore

    Rocky Moore Guest

    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:...
    > 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" <> wrote in message
    > news:...
    > > 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:...
    > > > 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" <> wrote in message
    > > > news:Ody$...
    > > > > 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=ShowTip&C=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
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Rocky Moore, Jan 13, 2004
    #5
  6. Rocky Moore

    Dan Brussee Guest

    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"
    <> 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.
     
    Dan Brussee, Jan 13, 2004
    #6
  7. Rocky Moore

    Rocky Moore Guest

    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" <> wrote in message
    news:...
    > 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"
    > <> 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.

    >
     
    Rocky Moore, Jan 14, 2004
    #7
  8. Rocky Moore

    mikeb Guest

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

    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" <> wrote in message
    > news:...
    >
    >>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"
    >><> 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
     
    mikeb, Jan 14, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Salerno
    Replies:
    20
    Views:
    859
    John Salerno
    Aug 11, 2006
  2. Fabio Z Tessitore

    who is simpler? try/except/else or try/except

    Fabio Z Tessitore, Aug 12, 2007, in forum: Python
    Replies:
    5
    Views:
    378
  3. David House

    try -> except -> else -> except?

    David House, Jul 6, 2009, in forum: Python
    Replies:
    2
    Views:
    337
    Bruno Desthuilliers
    Jul 6, 2009
  4. Peng Yu
    Replies:
    1
    Views:
    519
    Steven D'Aprano
    Nov 18, 2009
  5. MRAB
    Replies:
    0
    Views:
    827
Loading...

Share This Page