RE: regex help (Almost)
The regex works for most cases... but it's not stopping at the next ending tag... For example, the quote replac regex... I have [quote]heres a quote[/quote] Here's some text [quote]here's another quote[/quote] The expression replaces quote tags with blockquote tags unless it false between [code][/code] tags (which it doesntin this case) The result is blockquoteheres a quote[/quote] Heres some text [quote]here's another quote/blockquote Which of course should be blockquoteHeres a quote/blockquote Heres some text blockquotehere's another quote/blockquote This is the regex thats causing this... str = rereplace(str, (\[quote\](.*)\[/quote\])(?!((?!\[code\]).)*?\[/code\]), blockquote\2/blockquote, ALL); How can I change it to stop at the first [/quote] tag? -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.6.12 - Release Date: 1/14/2005 ~| Purchase Dreamweaver with Homesite Plus from House of Fusion, a Macromedia Authorized Affiliate and support the CF community. http://www.houseoffusion.com/banners/view.cfm?bannerid=54 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:190633 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
RE: regex help (Almost)
Are you using CFMX? If so you can specify minimal matching, which I think is probably the only way you can do this using a single regex. I think you replace .* with .*? -Original Message- From: Ewok [mailto:[EMAIL PROTECTED] Sent: Monday, 17 January 2005 10:01 a.m. To: CF-Talk Subject: RE: regex help (Almost) The regex works for most cases... but it's not stopping at the next ending tag... For example, the quote replac regex... I have [quote]heres a quote[/quote] Here's some text [quote]here's another quote[/quote] The expression replaces quote tags with blockquote tags unless it false between [code][/code] tags (which it doesntin this case) The result is blockquoteheres a quote[/quote] Heres some text [quote]here's another quote/blockquote Which of course should be blockquoteHeres a quote/blockquote Heres some text blockquotehere's another quote/blockquote This is the regex that's causing this... str = rereplace(str, (\[quote\](.*)\[/quote\])(?!((?!\[code\]).)*?\[/code\]), blockquote\2/blockquote, ALL); How can I change it to stop at the first [/quote] tag? -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.6.12 - Release Date: 1/14/2005 ~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:190634 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
RE: regex help (Almost)
Regular expressions are greedy by default, they match as much as they can. Adding ? to a qualifier makes it non-greedy - this seemed to do the job for me, but I haven't looked too closely at your expression. str = rereplace(str, (\[quote\](.*?)\[/quote\])(?!((?!\[code\]).)*?\[/code\]), blockquote\2/blockquote, ALL) -Original Message- From: Ewok [mailto:[EMAIL PROTECTED] Sent: Monday, 17 January 2005 10:01 a.m. To: CF-Talk Subject: RE: regex help (Almost) The regex works for most cases... but it's not stopping at the next ending tag... For example, the quote replac regex... I have [quote]heres a quote[/quote] Here's some text [quote]here's another quote[/quote] The expression replaces quote tags with blockquote tags unless it false between [code][/code] tags (which it doesntin this case) The result is blockquoteheres a quote[/quote] Heres some text [quote]here's another quote/blockquote Which of course should be blockquoteHeres a quote/blockquote Heres some text blockquotehere's another quote/blockquote This is the regex that's causing this... str = rereplace(str, (\[quote\](.*)\[/quote\])(?!((?!\[code\]).)*?\[/code\]), blockquote\2/blockquote, ALL); How can I change it to stop at the first [/quote] tag? -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.6.12 - Release Date: 1/14/2005 ~| Stay Ahead of Hackers - Download ZoneAlarm Pro http://www.houseoffusion.com/banners/view.cfm?bannerid=65 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:190635 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
RE: regex help (Almost)
MAN! How simple was that! Uhgg thanks guys -Original Message- From: Mike Nicholls [mailto:[EMAIL PROTECTED] Sent: Sunday, January 16, 2005 4:11 PM To: CF-Talk Subject: RE: regex help (Almost) Regular expressions are greedy by default, they match as much as they can. Adding ? to a qualifier makes it non-greedy - this seemed to do the job for me, but I haven't looked too closely at your expression. str = rereplace(str, (\[quote\](.*?)\[/quote\])(?!((?!\[code\]).)*?\[/code\]), blockquote\2/blockquote, ALL) -Original Message- From: Ewok [mailto:[EMAIL PROTECTED] Sent: Monday, 17 January 2005 10:01 a.m. To: CF-Talk Subject: RE: regex help (Almost) The regex works for most cases... but it's not stopping at the next ending tag... For example, the quote replac regex... I have [quote]heres a quote[/quote] Here's some text [quote]here's another quote[/quote] The expression replaces quote tags with blockquote tags unless it false between [code][/code] tags (which it doesntin this case) The result is blockquoteheres a quote[/quote] Heres some text [quote]here's another quote/blockquote Which of course should be blockquoteHeres a quote/blockquote Heres some text blockquotehere's another quote/blockquote This is the regex that's causing this... str = rereplace(str, (\[quote\](.*)\[/quote\])(?!((?!\[code\]).)*?\[/code\]), blockquote\2/blockquote, ALL); How can I change it to stop at the first [/quote] tag? -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.6.12 - Release Date: 1/14/2005 ~| Get help! RoboHelp http://www.houseoffusion.com/banners/view.cfm?bannerid=58 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:190636 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
RE: regex help (Almost)
Incase you havent realized regex's arent my forte! This seems to be the last little kink to get out of this thing and it will be set (or I'm going back to the original Jim Davis loop!) str = rereplace(str, (\[hr\])(?!(?!\[code\]).*?\[/code\]), hr, ALL); this regex works perfectly as long as the string doesn't contain [code][\code] blocks and doesn't have any single tags BEFORE the code (like [hr]) if there are code blocks then the above regex will only replace [hr] with hr AFTER the [code][/code] tags and leave any [hr]'s that come before it unchanged it doesn't replace the [hr]'s that fall inside the [code][/code] blocks either but that's what it's supposed to do, so apparently what it equates to is... replace [hr] if its after the last [/code] tag found and it should be... replace [hr] unless its after any [code] tag AND before the NEXT [/code] tag this block ... [hr] [code][b]some code[/b][/code] [hr] [code][b]some code[/b][/code] [hr] Is transformed into... [hr] pre[b]some code[/b]/pre [hr] pre[b]some code[/b]/pre hr The first 2 [hr] tags should be hr everything else works fine. just when I thought that I was actually getting better at regular expressions... sigh That is just the regex for tags without closing tags. The other regex for tags that have open and close works great like [b][/b] str = rereplace(str, (\[b\]([Aa-zZ0-9\s]*)\[/b\])(?!((?!\[code\]).)*?\[/code\]), b\2/b, ALL); cf-talk... Pimp my regex! Sorry... couldnt resist :) -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 1/16/2005 ~| Get help! RoboHelp http://www.houseoffusion.com/banners/view.cfm?bannerid=58 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:190653 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: regex help (Almost)
Still fighting that thing, eh? I spent 3 hours this afternoon trying to figure out why a simple INSERT query wouldn't work... finally I wrapped the query text in ## and a cfoutput, then copy/pasted it into Query Analyzer... only to find out that the problem was a new column in the database that was marked not nullable. I hadn't updated the insert to account for the new column. DANG, I hate when that happens. But, my my thought is this... Why not convert every single HR or BR tag to hr, then run rereplace with a regex that finds [\[code\].hr.\[\/code\]] and converts hr back to [HR]. Granted, it may not be the utmost in elegance (which is never pleasing), but it would work. Just a thought... I'll keep thinking on it too. Hard as that whole thinking thing may be. Laterz, J On Sun, 16 Jan 2005 19:11:27 -0500, Ewok [EMAIL PROTECTED] wrote: Incase you haven't realized regex's aren't my forte! This seems to be the last little kink to get out of this thing and it will be set (or I'm going back to the original Jim Davis loop!) str = rereplace(str, (\[hr\])(?!(?!\[code\]).*?\[/code\]), hr, ALL); this regex works perfectly as long as the string doesn't contain [code][\code] blocks and doesn't have any single tags BEFORE the code (like [hr]) if there are code blocks then the above regex will only replace [hr] with hr AFTER the [code][/code] tags and leave any [hr]'s that come before it unchanged it doesn't replace the [hr]'s that fall inside the [code][/code] blocks either but that's what it's supposed to do, so apparently what it equates to is... replace [hr] if its after the last [/code] tag found and it should be... replace [hr] unless its after any [code] tag AND before the NEXT [/code] tag this block ... [hr] [code][b]some code[/b][/code] [hr] [code][b]some code[/b][/code] [hr] Is transformed into... [hr] pre[b]some code[/b]/pre [hr] pre[b]some code[/b]/pre hr The first 2 [hr] tags should be hr everything else works fine. just when I thought that I was actually getting better at regular expressions... sigh That is just the regex for tags without closing tags. The other regex for tags that have open and close works great like [b][/b] str = rereplace(str, (\[b\]([Aa-zZ0-9\s]*)\[/b\])(?!((?!\[code\]).)*?\[/code\]), b\2/b, ALL); cf-talk... Pimp my regex! Sorry... couldn't resist :) -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 1/16/2005 -- Continuum Media Group LLC Burnsville, MN 55337 http://www.web-relevant.com http://cfobjective.blogspot.com ~| Find out how CFTicket can increase your company's customer support efficiency by 100% http://www.houseoffusion.com/banners/view.cfm?bannerid=49 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:190657 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
RE: regex help (Almost)
At least I'm not alone :) I had thought about something to that effect but... I wanted content between [code] and [/code] to stay exactly as the user typed it. So if there are b tags they display as b and if there are [b] tags they display as [b] Jim Davis came up with a loop that extracts code blocks and replaces them with a marker... then you can just do your replaces on everything then replace the markers with the original code blocks and voila! It worked well but my assumption was that a regular expression that can replace an open tag and an end tag and at the same time make the decision on rather or not it's between [code] and [/code] would be much faster. I'm at the point where I'll probably just combine both and move on with my life. Thanks for the thoughts, and watch those non-nullable fields! :) -Original Message- From: Jared Rypka-Hauer - CMG, LLC [mailto:[EMAIL PROTECTED] Sent: Sunday, January 16, 2005 8:24 PM To: CF-Talk Subject: Re: regex help (Almost) Still fighting that thing, eh? I spent 3 hours this afternoon trying to figure out why a simple INSERT query wouldn't work... finally I wrapped the query text in ## and a cfoutput, then copy/pasted it into Query Analyzer... only to find out that the problem was a new column in the database that was marked not nullable. I hadn't updated the insert to account for the new column. DANG, I hate when that happens. But, my my thought is this... Why not convert every single HR or BR tag to hr, then run rereplace with a regex that finds [\[code\].hr.\[\/code\]] and converts hr back to [HR]. Granted, it may not be the utmost in elegance (which is never pleasing), but it would work. Just a thought... I'll keep thinking on it too. Hard as that whole thinking thing may be. Laterz, J -- No virus found in this incoming message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 1/16/2005 -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 1/16/2005 ~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:190662 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: regex help (Almost)
Geeze, I sure hope anyone who read this paragraph: Still fighting that thing, eh? I spent 3 hours this afternoon trying to figure out why a simple INSERT query wouldn't work... finally I wrapped the query text in ## and a cfoutput, then copy/pasted it into Query Analyzer... only to find out that the problem was a new column in the database that was marked not nullable. I hadn't updated the insert to account for the new column. Knew I was speaking in shorthand. It's embarrasing. I mean, I pulled it out of the cfquery tag, wrapped it in a cfoutput instead, and rendered the text as-was to the screen... so I had my query, verbatim, as the cfquery tag would be receiving it. Then I copy/pasted THAT into query analyzer, so I could get the actual SQL Server error that was screwing me up. I haven't always been really good about my error handling, because, I guess, I've always thought that if you make the system so it works well, you don't get errors. And, mostly, it's held true. But, times like today remind me that error handling isn't just for end users... it's more for us than anything, because if we do it right, it'll TELL us what's wrong most of the time. Anyway... good luck with your regexes! Laterz, J On Sun, 16 Jan 2005 22:31:51 -0500, Ewok [EMAIL PROTECTED] wrote: At least I'm not alone :) I had thought about something to that effect but... I wanted content between [code] and [/code] to stay exactly as the user typed it. So if there are b tags they display as b and if there are [b] tags they display as [b] Jim Davis came up with a loop that extracts code blocks and replaces them with a marker... then you can just do your replaces on everything then replace the markers with the original code blocks and voila! It worked well but my assumption was that a regular expression that can replace an open tag and an end tag and at the same time make the decision on rather or not it's between [code] and [/code] would be much faster. I'm at the point where I'll probably just combine both and move on with my life. Thanks for the thoughts, and watch those non-nullable fields! :) -- Continuum Media Group LLC Burnsville, MN 55337 http://www.web-relevant.com http://cfobjective.blogspot.com ~| Protect your mail server with built in anti-virus protection. It's not only good for you, it's good for everybody. http://www.houseoffusion.com/banners/view.cfm?bannerid=39 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:190663 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
RE: regex help (Almost)
Dude, have you considered taking a online Computer related stress test or lowering your caffeine intake? Hah jokes. Believe me... we've all been there... just some more than others. :) -Original Message- From: Jared Rypka-Hauer - CMG, LLC [mailto:[EMAIL PROTECTED] Sent: Sunday, January 16, 2005 10:45 PM To: CF-Talk Subject: Re: regex help (Almost) Geeze, I sure hope anyone who read this paragraph: Still fighting that thing, eh? I spent 3 hours this afternoon trying to figure out why a simple INSERT query wouldn't work... finally I wrapped the query text in ## and a cfoutput, then copy/pasted it into Query Analyzer... only to find out that the problem was a new column in the database that was marked not nullable. I hadn't updated the insert to account for the new column. Knew I was speaking in shorthand. It's embarrasing. I mean, I pulled it out of the cfquery tag, wrapped it in a cfoutput instead, and rendered the text as-was to the screen... so I had my query, verbatim, as the cfquery tag would be receiving it. Then I copy/pasted THAT into query analyzer, so I could get the actual SQL Server error that was screwing me up. I haven't always been really good about my error handling, because, I guess, I've always thought that if you make the system so it works well, you don't get errors. And, mostly, it's held true. But, times like today remind me that error handling isn't just for end users... it's more for us than anything, because if we do it right, it'll TELL us what's wrong most of the time. Anyway... good luck with your regexes! Laterz, J On Sun, 16 Jan 2005 22:31:51 -0500, Ewok [EMAIL PROTECTED] wrote: At least I'm not alone :) I had thought about something to that effect but... I wanted content between [code] and [/code] to stay exactly as the user typed it. So if there are b tags they display as b and if there are [b] tags they display as [b] Jim Davis came up with a loop that extracts code blocks and replaces them with a marker... then you can just do your replaces on everything then replace the markers with the original code blocks and voila! It worked well but my assumption was that a regular expression that can replace an open tag and an end tag and at the same time make the decision on rather or not it's between [code] and [/code] would be much faster. I'm at the point where I'll probably just combine both and move on with my life. Thanks for the thoughts, and watch those non-nullable fields! :) -- Continuum Media Group LLC Burnsville, MN 55337 http://www.web-relevant.com http://cfobjective.blogspot.com ~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:190664 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: regex help (Almost)
:P I just read the note I sent and thought Good god, that sucked. Figured if I thought it, someone else probably did too. But then, we're all our own worse critics... And I only got 2 cups of coffee today... every time I went to fill my cup, the pot was empty. Hey, maybe that's the problem... not ENOUGH caffeine. Laterz, J On Sun, 16 Jan 2005 22:56:54 -0500, Ewok [EMAIL PROTECTED] wrote: Dude, have you considered taking a online Computer related stress test or lowering your caffeine intake? Hah jokes. Believe me... we've all been there... just some more than others. :) -- Continuum Media Group LLC Burnsville, MN 55337 http://www.web-relevant.com http://cfobjective.blogspot.com ~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:190665 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54