|
View:
New views
10 Messages
—
Rating Filter:
Alert me
|
|
|
Trying to find ";"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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1149 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21 |
|
|
Re: Trying to find ";"On Thu, Jul 10, 2008 at 10:08 AM, Patrick Santora <patweb99@...> wrote:
> 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. 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? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1150 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21 |
|
|
Re: Trying to find ";">On Thu, Jul 10, 2008 at 10:08 AM, Patrick Santora <patweb99@...> 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; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1151 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21 |
|
|
Re: Trying to find ";"> 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) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1152 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21 |
|
|
Re: Trying to find ";"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@...> wrote: > > 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) > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1153 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21 |
|
|
Re: Trying to find ";"> 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. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1154 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21 |
|
|
Re: Trying to find ";"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@...> wrote: > > 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. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1155 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21 |
|
|
Re: Trying to find ";"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@...> wrote: > > 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. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1156 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21 |
|
|
Re: Trying to find ";"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> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1157 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21 |
|
|
Re: Trying to find ";"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@...> wrote: > 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> > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1158 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21 |
| Free embeddable forum powered by Nabble | Forum Help |