Start by simplifying the regex:
<cfset reg = """[^""]+/([^""/]+\.(jpg|gif|png))""" />
(It just gets every image reference inside double-quotes.)
Then use REMatchNoCase() to get an array of all matches:
<cfset test = reMatchNoCase(reg, string) />
(REFindNoCase() only gets one match, so it only works if you put it
inside a conditional loop.)
Then loop over the array and get the last "list" element using the "/"
as the delimiter (and also strip out the trailing quote):
<cfoutput>
<cfloop array="#test#" index="a">
#listLast(listLast(a, """"), "/")#
<br />
</cfloop>
</cfoutput>
On 11/18/2011 7:32 PM, marc -- wrote:
> Hi,
>
> I have a series of texts, each of which I want to search for the occurence of
> links to images. From each text I want to extract image filenames that end on
> one of these strings:
>
> .gif,.jpg,.jpeg,.png,.bmp
>
> Searching a text containing the string
>
> <img src="http://my.domain.com/path/to/images/testimg.gif">
>
> would give me testimg.gif,
>
> searching a text containing the strings
> <img src="http://my.domain.com/path/to/images/testimg.gif">
> <img src="http://my.domain.com/path/to/images/testimg.jpg">
> <img src="http://my.domain.com/path/to/images/testimg.png">
>
> would give me
>
> testimg.gif,testimg.jpg,testimg.png
>
> I think REFindNoCase is most suitable for this since it's the only CF
> function that lets me search for multiple occurences of a pattern I know of.
> I can't get it to match _all_ occurences of the string I'm looking for.
>
> The regular expression I use:
> (<img src ?= ?[""|'][https?://]?[a-zA-Z0-9_\-/\\\.^\.jpg]+\.jpg)\s?(\1)*
>
> I do this:
> REFindNoCase(RE,string,1,"true") where RE is the above regular expression and
> string is the string containing 3<img> tags with an .jpg resource.
>
> This gives me an array containing the starting position and the length of the
> _first_ element in the string that matches with the regular expression. I
> can't get it to include all matches in the string.
>
> Is my regular expression wrong or is it not possible what I want?
>
> Marc
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:348830
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm