8 Replies Latest reply on Jun 15, 2007 1:05 AM by Novice2002

    ReReplace?

    Novice2002 Level 1
      Please have look at the paragraph below

      <p>Unfortunately it's not possible to see at once which radio button in a group the user has checked. You need to go through all radio's and see which one's <code>checked</code> property is true</p>
      <p><img alt="" height="158" src="/univadis/userfiles/Image/BlissStarWars_15.jpg" width="210"/></p>

      Is it possible to replace the image tag with the tags below?
      <ContentItem Duid="Photo47" Href="news20070613_122.jpg">
      <MediaType FormalName="Photo"/>
      Format FormalName="jpg"/>
      </ContentItem>

      Thanks
        • 1. Re: ReReplace?
          insuractive Level 3
          I guess my first question is - how do you identify which particular graphic to replace? are you always trying to replace the BlissStarWars_15.jpg graphic? The first graphic after the "Unfortunately" paragraph?
          • 2. Re: ReReplace?
            Novice2002 Level 1
            I basically want to replace the image tag anywhere within the body text nothwithstanding the image name.

            This is the star wars triology the image below should enhance things <img alt="" height="158" src="/uploads/Image/BlissStarWars_15.jpg" width="210"/> We shall seesdfsdfsdf <img alt="" height="158" src="/uploads/Image/obi_1.jpg" width="210"/> and the story continues..

            all I want to do is to remove the image tags from the body of text and replace it with the values in the "src" attributes, BlissStarWars_15.jpg and obi_1.jpg at their respective positions...

            Thanks
            • 3. Re: ReReplace?
              Novice2002 Level 1
              I think I've got a bit close to solving this but as my regex skill is not very good, I've had to do an overnight crash course on it, I'm not sure what I'm doing wrong with the tag below, it's coming up with a missing argument error.

              <cfset content = reReplaceNoCase(dataContent,'<img.*?src=['|"](.*?)['|"].*?>',"\1","ALL")>

              Help please..
              • 4. Re: ReReplace?
                Level 7
                hte foollowing regexp will replace all img tags with just the filename
                (without any filepath) from the img tag's src attribute:

                <cfset content = REReplaceNoCase(dataContent,
                "<img([^src]*)(src=['|""])([/*[[:alnum:]]*/]*)([^""]*)[^>]*>", "\4", "ALL")>

                could very likely be optimized further, but it does the trick...

                --

                Azadi Saryev
                Sabai-dee.com
                http://www.sabai-dee.com
                • 5. Re: ReReplace?
                  Novice2002 Level 1
                  That is the one Azadi! That seems to do the trick, thanks a million. I'll have to brush up on my Regex skills, it's a top tool to have in the armoury.

                  Thanks again.
                  • 6. Re: ReReplace?
                    Novice2002 Level 1
                    Hi Azadi -

                    Don't know if you're still there. I have been trying to tweak/extend your solution. Basically the ultimate aim is to capture the image tags in the body text and replace it with the following tags;

                    <ContentItem Duid="Photo47" Href="news20070613_122.jpg">
                    <MediaType FormalName="Photo"/>
                    Format FormalName="jpg"/>
                    </ContentItem>

                    My dab at it is the following which is again giving me a missing argument error;

                    <cfset before = '<ContentItem Href="'><cfsavecontent variable="after"> " Duid="hard coded"> <Comment>hard coded</Comment> <MediaType FormalName="hard coded"/> <Format FormalName="hard coded"/> </ContentItem></cfsavecontent>>

                    <cfset content = reReplaceNoCase(dataContent,'<img([^src]*)(src=['|""])([/*[[:alnum:]]*/]*)([^""]*)[^>]*>' ,'#before#\4#after#','all')>

                    What am I doing wrong please?

                    Thanks
                    • 7. Re: ReReplace?
                      insuractive Level 3
                      Your syntax looks a little off in your <cfset>/<cfsavecontent> statement - I think you might have some problems escaping your quotes / single quotes.

                      Try This:
                      <!--- you can escape quotes with 2x --->
                      <cfset before = "<ContentItem Href=""">
                      <!--- after text --->
                      <cfsavecontent variable="after">
                      " Duid="hard coded"> <Comment>hard coded</Comment> <MediaType FormalName="hard coded"/> <Format FormalName="hard coded"/> </ContentItem>
                      </cfsavecontent>

                      <cfset sPattern = "<img([^src]*)(src=['|""""])([/*[[:alnum:]]*/]*)([^""""]*)[^>]*>">
                      <cfset content = reReplaceNoCase(dataContent,sPattern,"#before#\4#after#","all")>
                      • 8. Re: ReReplace?
                        Novice2002 Level 1
                        I've sorted it out by getting rid of CFSaveContent, see the solution below.

                        <cfset content = rereplace(dataContent, "<img([^src]*)(src=['|""])([/*[[:alnum:]]*/]*)([^""]*)[^>]*>", "<contentItem Href=""\4""><Comment>hardcoded</Comment> <MediaTypeFormalName=""hardcoded""/> <Format FormalName=""hard coded""/><contentitem>", "all")>

                        Thanks