|
Mailing Lists
|
Home /
Groups /
Regular Expressions (RegEx)
Trying to find ";"
Hey everyone,Patrick Santora 07/10/08 10:11 A On Thu, Jul 10, 2008 at 10:08 AM, Patrick Santora <patweb99@gmail.com> wrote:Rob Wilkerson 07/10/08 10:23 A >On Thu, Jul 10, 2008 at 10:08 AM, Patrick Santora <patweb99@gmail.com> wrote:Patrick Santora 07/10/08 10:35 A > I am trying to find ";" ONLY at the end of a string and not within (like within single orPeter Boughton 07/10/08 11:31 A hmm. I'm not sure if that will work for me as I don't want to try to alterPatrick Santora 07/10/08 11:49 A > hmm. I'm not sure if that will work for me as I don't want to try to alterPeter Boughton 07/10/08 12:04 P Let me rephrase what I stated before. Your approach should work fine, but IPatrick Santora 07/10/08 12:25 P Peter,Patrick Santora 07/10/08 12:33 P Yes, it's very easy to get carried away with overthinking regex - I'vePeter Boughton 07/10/08 01:00 P Ahh I see, yeah that could pose and issue. I will check out what you sentPatrick Santora 07/10/08 01:15 P 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 = ""edString=value"; sScoped = '"edString=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 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? >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; > 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) 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 ----- > 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. 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 ----- 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 ----- 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> 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 -----
|
May 19, 2013
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||