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

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

Regex Gunslingers

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Josh Nathanson
11/13/2007 12:21 PM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Doom
11/13/2007 02:18 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Andy Matthews
11/13/2007 04:31 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Barney Boisvert
11/13/2007 05:44 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Nadel
11/14/2007 09:25 AM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Doom
11/14/2007 10:07 AM

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


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

Search cf-talk

October 20, 2014

<<   <   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