If you search the cf-regex archives, they're full of stuff like this. It's a common problem.
What you are seeing (I suspect) is the regex grabbing everything from the <div id="whatever"> to the last </div>. This is because regex, by default, uses greedy matching. In CFMX, you can do a non-greedy match like so: "<div id="newsletterBody">(.*?)</div>" In CF5, the easy shortcut is to turn the </div>s into something untypable -- I like the bell symbol for no real reason. bell = chr(7) So, string = replacenocase(string, "</div>", "#chr(7)#", "all"); string = rereplacenocase(string, "<div id="whatever">([^#chr(7)#]*)#chr(7)#", "whatever"); If you want to discuss this more in depth, I suggest we shlep on over to http://www.houseoffusion.com/cf_lists/index.cfm?method=threads&forumid=21 where we can discuss this on-topic, in depth, and with a good number of very smart regexers. :-) -- Ben Doom Programmer & General Lackey Moonbow Software, Inc : -----Original Message----- : From: mayo [mailto:[EMAIL PROTECTED] : Sent: Saturday, August 02, 2003 4:04 PM : To: CF-Talk : Subject: REReplace not working as it should ... or is it me? -- : REWRITTEN : : : I'm creating a system to allow some users update parts of their site. : : 1. I'm using CFFILE action="read" to pull the file. : 2. Then I'm pulling out sections within divs to be replaced. : 3. These sections are placed in forms allowing users to update : them and then : using CFFILE to update the file by writing over the existing file. : : OK, so far so good. The problem is in the regex. It works -- but not as it : should?!? : : <cfset title = REreplace(readFile,'^.*<div : id="newsletterBody">(.*)</div>.*$','\1','all')> : : I read the regex above as : : Scan through string readFile : : 1. start at the begining ^.* : 2. find <div id="newsletterBody">(.*)</div> : 3. group 1 is everything between the <div>s : : That DIDN'T WORK !!! OK, what to do? Let's put a stop. Search for : everything : except for a ">" : : 4. Replace (.*) with ([^>]*) : This worked fine except for the fact that there are <P>s and <BR>s. : Alrightly then use a @ as the stop. : 5. I replaced ([^>]*) with ([EMAIL PROTECTED]) and put a @ between the <div>s. That : didn't work!!! : 6. After much fumbling I put the @ after the <div>s. That worked. : Go figure? : : QUESTION: : : Isn't group 1 ([EMAIL PROTECTED]) between the <div>s. Why would the @ work outside : the <div>s? : : : I have : <div id="newsletterBody"> : lorem ipsum whatever<P> : lorem ipsum more<P> : stuff<P> : </div><!-- @ --> : : Thanks for any insight. : : Gilbert Midonnet : : : : : : : : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Signup for the Fusion Authority news alert and keep up with the latest news in ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4