regular expression - injecting div, and removing later

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stimp

    regular expression - injecting div, and removing later

    Hi all,

    I'm having trouble trying to figure out the best approach to this
    problem and I believe regular expressions are the way to go.

    Basically I have created a large string of XHTML using a WYSIWYG editor,
    so the string is like "<p>dfdsfjh ds <img src='temp.jpg' />
    dsfdsfsd</p><p>dfsdfsdfsd </p... "

    What I want to do is the following...

    When SAVING the string to the database I want to replace:

    <img class="myImg" alt="" src="image.jpg" />

    with...

    <div class="cnt_myIm g_left">
    <div class="inner">
    <img class="myImg" alt="" src="image.jpg" />
    <p class="sub_text detail">my picture</p>
    </div>
    </div>


    and when EDITING the string, I want to reinstate the original ....so
    replace:

    <div class="cnt_myIm g_left">
    <div class="inner">
    <img class="myImg" alt="" src="image.jpg" />
    <p class="sub_text detail">my picture</p>
    </div>
    </div>

    with...

    <img class="tmceImg" alt="" src="image.jpg" />


    Does anyone know the best approach to this?

    Many thanks!
    Peter
    --

    fiddlewidawiddu m
  • Alexey Smirnov

    #2
    Re: regular expression - injecting div, and removing later

    On Aug 2, 12:08 pm, Stimp <r...@spumco.co mwrote:
    Hi all,
    >
    I'm having trouble trying to figure out the best approach to this
    problem and I believe regular expressions are the way to go.
    >
    Basically I have created a large string of XHTML using a WYSIWYG editor,
    so the string is like "<p>dfdsfjh ds <img src='temp.jpg' />
    dsfdsfsd</p><p>dfsdfsdfsd </p... "
    >
    What I want to do is the following...
    >
    When SAVING the string to the database I want to replace:
    >
    <img class="myImg" alt="" src="image.jpg" />
    >
    with...
    >
    <div class="cnt_myIm g_left">
     <div class="inner">
       <img class="myImg" alt="" src="image.jpg" />
       <p class="sub_text detail">my picture</p>
     </div>
    </div>
    >
    and when EDITING the string, I want to reinstate the original ....so
    replace:
    >
    <div class="cnt_myIm g_left">
     <div class="inner">
       <img class="myImg" alt="" src="image.jpg" />
       <p class="sub_text detail">my picture</p>
     </div>
    </div>
    >
    with...
    >
    <img class="tmceImg" alt="" src="image.jpg" />
    >
    Does anyone know the best approach to this?
    >
    Many thanks!
    Peter
    --
    >
    fiddlewidawiddu m
    Well, I think you already found that this can be done using
    Regex.Replace function. It allows replacement of text using regular
    expressions. Not only can you define the text to replace using a
    regular expression, you can define what to replace it with using a
    replacement string containing special constructs which identify
    portions of the mathed text.

    More about this function
    In a specified input string, replaces strings that match a regular expression pattern with a specified replacement string.

    Comment

    • Stimp

      #3
      Re: regular expression - injecting div, and removing later

      On Sat, 2 Aug 2008 Alexey Smirnov <alexey.smirnov @gmail.comwrote :
      On Aug 2, 12:08 pm, Stimp <r...@spumco.co mwrote:
      >
      Well, I think you already found that this can be done using
      Regex.Replace function. It allows replacement of text using regular
      expressions. Not only can you define the text to replace using a
      regular expression, you can define what to replace it with using a
      replacement string containing special constructs which identify
      portions of the mathed text.
      >
      More about this function
      http://msdn.microsoft.com/en-us/libr...x.replace.aspx

      thanks worked a charm! - plus I learned some regex.. bonus :)

      --

      fiddlewidawiddu m

      Comment

      Working...