|
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Regex Gunslingers
Hey all,Josh Nathanson 11/13/07 12:21 P Actually, that's not all that easy. Regex is great for tokenizing, butBen Doom 11/13/07 02:18 P Just wait for Barney...he'll have an answer I'll bet.Andy Matthews 11/13/07 04:31 P Sadly no. Ben's right, regex isn't very good at this sort of problem,Barney Boisvert 11/13/07 05:44 P A while back I wrote a custom tag for iterating over regular expressionBen Nadel 11/14/07 09:25 A Pretty slick.Ben Doom 11/14/07 10:07 A Hey all, Got a regex challenge...I was able to solve it using an REFind and then REReplace, but I'm wondering if anyone can come with a "one-shot" way to replace without looping. I need to remove any carriage returns within a quoted string, but not touch them if they are outside quotes. So: "the quick brown fox \r\n jumps over the \r\n lazy dog" <-- remove the \r\n's My name is mud \r\n <-- leave this one alone I'm sure this is probably easy for the regex gurus... -- Josh Actually, that's not all that easy. Regex is great for tokenizing, but not parsing. There are ways to determine whether or not you are "inside" quotes, but in my experience, looping usually gives you the best results -- especially when the text is not precicely what you expect. For example, quotes doubled to escape them, unclosed quotes, etc. --Ben Doom Josh Nathanson wrote: ----- Excess quoted text cut - see Original Post for more ----- Just wait for Barney...he'll have an answer I'll bet. Actually, that's not all that easy. Regex is great for tokenizing, but not parsing. There are ways to determine whether or not you are "inside" quotes, but in my experience, looping usually gives you the best results -- especially when the text is not precicely what you expect. For example, quotes doubled to escape them, unclosed quotes, etc. --Ben Doom Josh Nathanson wrote: ----- Excess quoted text cut - see Original Post for more ----- Sadly no. Ben's right, regex isn't very good at this sort of problem, because you can't match the same portion of the string in two different ways. If you could constrain the problem so that there was never more than one newline per quoted string, then you could do it. Without that restriction, however, I believe you're stuck either only replacing the first newline per string, or potentially replacing some outside quotes, because you can't check both ends of the quoted range. cheers, barneyb On Nov 13, 2007 1:29 PM, Andy Matthews <lists@commadelimited.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- A while back I wrote a custom tag for iterating over regular expression patterns. I think this would be a great use for it. I wrote up an example based on the proposed question: http://www.bennadel.com/blog/1037-RELoop-ColdFusion-Custom-Tag-Case-Stud y.htm Or - http://bennadel.com/index.cfm?dax=blog:1037.view Hope that helps. ..................... Ben Nadel Certified Advanced ColdFusion MX7 Developer www.bennadel.com Need ColdFusion Help? www.bennadel.com/ask-ben/ ----- Excess quoted text cut - see Original Post for more ----- "one-shot" ----- Excess quoted text cut - see Original Post for more ----- Pretty slick. --Ben Doom Ben Nadel wrote: > A while back I wrote a custom tag for iterating over regular expression > patterns. I think this would be a great use for it. I wrote up an > example based on the proposed question: > > http://www.bennadel.com/blog/1037-RELoop-ColdFusion-Custom-Tag-Case-Stud > y.htm > Or - http://bennadel.com/index.cfm?dax=blog:1037.view
|
Mailing Lists
|
Latest Fusion Authority Articles
|
||||||