House of Fusion
Home of the ColdFusion Community

Search cf-talk

October 11, 2008

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

Subscribe Now
Fusion Authority Quarterly Update - ColdFusion 8 Special Edition
Search over 2,500 ColdFusion resources here  >>>      
Home /  Groups /  ColdFusion Talk (CF-Talk)

More RegEx fun (Negative lookaheads)

  << 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:
Will Tomlinson
07/03/2008 02:03 PM

I wanted to see if I could use a negative look ahead on this block of code to make sure if there's a var rbo=""; in the code, there must be a rbo = closeObj(); somewhere after it. Like so... <cfset str = ' <cfscript> var rbo = ""; var someVar = "Will"; var someOtherVar = "Whatever"; Whateverelse logic here... rbo = closeObj(); rbo = ""; '> I played around with a negative lookahead and it looks like a powerful regex tool... I just can't make it work. I gave up at the \2 <cfset re = '(.+)(var\srbo\s=\s"";)(\2)'> <cfoutput>#reFindNoCase(re, str)#</cfoutput> I'm trying to capture the whole chunk, capture the rbo line only, then lookahead to see if it's located in the rest of the whole chunk. Make sense? Thanks, Will

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
07/03/2008 02:05 PM

I didn't phrase that right. I want to check and make sure this is located after the var rbo line. I guess I could do one at a time. rbo = closeObj(); rbo = "";

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
07/03/2008 02:42 PM

Dangit. I can't make this flag it. It LOOKS like it'd work.   Find the first instance of the rbo call, then make sure it's closed AFTERwards. <cfset str = ' <cfscript> var rbo = ""; var someVar = "Will"; var someOtherVar = "Whatever"; Whateverelse logic here... rbo = closestObj(); rbo = ""; </cfscript> '> <cfset re = 'var\s(rbo\s=\s"";)(rbo\s=\scloseObj\(\);)\1(?!\2)'> <cfoutput>#reFindNoCase(re, str)#</cfoutput>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Nathan Strutz
07/03/2008 03:03 PM

Will, Lookaround doesn't work with ColdFusion's regex engine. Instead, use Java's: #str.matches(re)# (returns true/false) also look into replaceFirst, replaceAll and split. Ehh, I'd link my blog where I have a couple entries and a presentation on it, but I've been having DNS issues for a few days, and it looks like they'll continue through the next week... Instead, here's a link to java.lang.string - if you can do it in Java, you can do it in CF! http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html nathan strutz http://www.dopefly.com/ On Thu, Jul 3, 2008 at 11:38 AM, Will Tomlinson <will@wtomlinson.com> wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
07/03/2008 04:27 PM

>Will, > >Lookaround doesn't work with ColdFusion's regex engine. Instead, use Java's: > >#str.matches(re)# (returns true/false) > >also look into replaceFirst, replaceAll and split. Check this out too: http://www.bennadel.com/blog/769-Learning-ColdFusion-8-REMatch-For-Regular-Expression-Matching.htm But, until now, ColdFusion has been extremely weak when it came to retrieving substrings from a chunk of text using regular expressions. Thankfully, ColdFusion 8 has introduced REMatch() and REMatchNoCase(). REMatch() searches through a string using a regular expression and returns all matching patterns in an array.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
07/03/2008 04:47 PM

Wowee... in CF8, this works with a lookahead. <cfset str = ' <cfscript> var rbo = ""; var someVar = "Will"; var someOtherVar = "Whatever"; Whateverelse logic here... rbo = closeggObj(); rbo = ""; </cfscript> '> <cfset re = '(?!rbo\s=\s"";)\nvar\ssomeVar'> <cfset result = REMatchNoCase(re, str)> <cfdump var="#result#"> Returns an array: 1     var someVar

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Massimo Foti
07/03/2008 06:05 PM

> Lookaround doesn't work with ColdFusion's regex engine. Instead, use > Java's: As far as I remember lookaheads work, lookbehind don't. Please correct me if I am wrong. Will, if you want to use Java RegExp, you can try this CFC: http://www.massimocorner.com/coldfusion/cfc/tmt_java_regexp.zip ---------------------------- Massimo Foti, web-programmer for hire Tools for ColdFusion, JavaScript and Dreamweaver: http://www.massimocorner.com ----------------------------

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Patrick Santora
07/03/2008 09:17 PM

If you are using any Cold Fusion MX version you can use the underlying regex engine. I came into this thread late, but if this helps you then great. Take a look at the below blog to see what mean. This works with Cold Fusion version 6 to current. http://patweb99.avatu.com/post.cfm/how-to-access-underlying-java-regular-expression-functionality-in-coldfusion-to-get-around-re-function-limitations On Thu, Jul 3, 2008 at 3:01 PM, Massimo Foti <massimo@massimocorner.com> wrote: ----- Excess quoted text cut - see Original Post for more -----


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

Mailing Lists