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

Mailing Lists
Home /  Groups /  Regular Expressions (RegEx)

Trying to find ";"

  << 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:
Patrick Santora
07/10/2008 10:11 AM

Hey everyone, I am trying to find ";" ONLY at the end of a string and not within (like within single or double quotes). I believe I will need to use look aheads and look behinds which I have access too by using the underlying java regex engine in CF. Any ideas on what the expression should look like? Here is the strings to search against: sScoped = "&quotedString=value"; sScoped = '&quotedString=value'; sScoped = "&" & ";quotedString=value"; NOTE: This is for varScoper, so if you help me fix this i'm sure we can throw your name out on the next release. Thanks, Pat Santora http://patweb99.avatu.com

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rob Wilkerson
07/10/2008 10:23 AM

On Thu, Jul 10, 2008 at 10:08 AM, Patrick Santora <patweb99@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- At the risk of oversimplifying, could this be as easy as ";$"?  In other words, match any semicolon that appears as the last character in the line?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Patrick Santora
07/10/2008 10:35 AM

>On Thu, Jul 10, 2008 at 10:08 AM, Patrick Santora <patweb99@gmail.com> wrote: > >At the risk of oversimplifying, could this be as easy as ";$"?  In >other words, match any semicolon that appears as the last character in >the line? I don't think so as we also want to catch multiple variables being set to one line (should have put this in the original post): var1 = 1; var2 = 2;

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peter Boughton
07/10/2008 11:31 AM

> I am trying to find ";" ONLY at the end of a string and not within (like within single or > double quotes). > I don't think so as we also want to catch multiple variables being set to one line (should have put this in the original post): > var1 = 1; var2 = 2; So end of string is irrelevant? What you actually want to find is all semi-colons excluding those within quotes? In which case, just replace/remove quoted values first and then search for any semi-colons. Text = REReplace ( Text , '"([^"]|"")+"' , '{quotedstring}' , 'all') (and same again with single/double inverted)

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Patrick Santora
07/10/2008 11:49 AM

hmm. I'm not sure if that will work for me as I don't want to try to alter the text. I just want to ignore ";" within quotes hence why doing a look ahead / look behind may be an answer. I will keep your approach in mind though as it could work if I have to go down that road. On Thu, Jul 10, 2008 at 8:29 AM, Peter Boughton <boughtonp@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peter Boughton
07/10/2008 12:04 PM

> hmm. I'm not sure if that will work for me as I don't want to try to alter > the text. Why not? If you need the original text (e.g. for showing context of errors), then you just create a copy of the text and work on that, then refer back to the original version once you know which line numbers the errors are on.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Patrick Santora
07/10/2008 12:25 PM

Let me rephrase what I stated before. Your approach should work fine, but I would like to avoid removing characters if possible. I will definatly keep your idea in mind if I can't do with a look ahead/behind. The bottom line is I am just trying my best not to have to alter the code being searched. On Thu, Jul 10, 2008 at 9:01 AM, Peter Boughton <boughtonp@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Patrick Santora
07/10/2008 12:33 PM

Peter, I just may be overthinking this. heh. I am going to toss your idea in and see how it floats. It should work fine. I just may need to make some additional modifictions elsewhere in varScoper. Thanks for the quick assist. -Pat On Thu, Jul 10, 2008 at 9:01 AM, Peter Boughton <boughtonp@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peter Boughton
07/10/2008 01:00 PM

Yes, it's very easy to get carried away with overthinking regex - I've done it plenty of times. :) There may be situations where working with only the original text is required, but I couldn't think of any - once linebreaks are preserved it should be fine - and I think actually cutting out unwanted parts way is a simpler method. However, I have thought up a situation where the regex I supplied would fail... Consider this: varY = "ab#LCase("C;DEF;G")#hi"; The nested quotes inside the hashes are valid syntax, but confuse the regex, and the semicolons would be left when they shouldn't be. One way of solving that is to first strip all hashed variables - I think that makes sense, but haven't fully thought it through. Here's the quick test code I've thrown together for that: <cfsavecontent variable="reHashed">#([^#]|##)+#</cfsavecontent> <cfsavecontent variable="reDouble">"([^"]|"")+"</cfsavecontent> <cfsavecontent variable="reSingle">'([^']|'')+'</cfsavecontent> <cfoutput> <pre> #SourceText#<hr/> <cfset SourceCopy = jre.replace( SourceCopy , reHashed ,'{hashed}' , 'all' )/> #SourceCopy#<hr/> <cfset SourceCopy = jre.replace( SourceCopy , reDouble ,'{dquoted}' , 'all' )/> #SourceCopy#<hr/> <cfset SourceCopy = jre.replace( SourceCopy , reSingle  ,'{squoted}' , 'all' )/> #SourceCopy#<hr/> </pre> </cfoutput>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Patrick Santora
07/10/2008 01:15 PM

Ahh I see, yeah that could pose and issue. I will check out what you sent and let you know. I probably will not get to it until later today. Thanks Peter. On Thu, Jul 10, 2008 at 9:58 AM, Peter Boughton <boughtonp@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more -----


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

Search regex

May 19, 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