House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

How to search for all occurences of a string in a text?

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Hi,
marc --
11/18/11 07:32 P
Start by simplifying the regex:
Jason Fisher
11/18/11 08:22 P
Thanks, it works now!
marc --
11/19/11 07:18 A
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
marc --
11/18/2011 07:32 PM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Jason Fisher
11/18/2011 08:22 PM

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: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
marc --
11/19/2011 07:18 AM

Thanks, it works now!


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 22, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Designer, Developer and mobile workflow conference