• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ReReplace?

New Here ,
Jun 13, 2007 Jun 13, 2007

Copy link to clipboard

Copied

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
TOPICS
Advanced techniques

Views

656

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 14, 2007 Jun 14, 2007
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

Votes

Translate

Translate
Advocate ,
Jun 13, 2007 Jun 13, 2007

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 13, 2007 Jun 13, 2007

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 14, 2007 Jun 14, 2007

Copy link to clipboard

Copied

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..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 14, 2007 Jun 14, 2007

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 14, 2007 Jun 14, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 14, 2007 Jun 14, 2007

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 14, 2007 Jun 14, 2007

Copy link to clipboard

Copied

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")>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 15, 2007 Jun 15, 2007

Copy link to clipboard

Copied

LATEST
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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation