Thursday, August 28, 2008    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< May 2007 >>
S M T W T F S
    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    

Search

Categories
 • Acrobat (1) [RSS]
 • Adobe (66) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (21) [RSS]
 • AIR (124) [RSS]
 • Appearances (118) [RSS]
 • Books (68) [RSS]
 • CFEclipse (14) [RSS]
 • ColdFusion (1138) [RSS]
 • Data Services (12) [RSS]
 • Flash (101) [RSS]
 • Flex (362) [RSS]
 • Home Automation (2) [RSS]
 • Jobs (91) [RSS]
 • JRun (12) [RSS]
 • Labs (27) [RSS]
 • LiveCycle (21) [RSS]
 • MAX (156) [RSS]
 • Regular Expressions (12) [RSS]
 • RIA (4) [RSS]
 • SQL (37) [RSS]
 • Stuff (503) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (135) [RSS]
 • Wireless (97) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
May 4, 2007

Scorpio Adds Two New RegEx Functions

ColdFusion has supported Regular Expressions for a while, but I've always missed a REMatch() function, one that would locate all matches and return them. Over the years several of us have written our own functions to do this, but that's no longer needed - REMatch() and REMatchNoCase() are both in Scorpio.

TrackBacks
There are no trackbacks for this entry.

No trackback URL. Trackbacks are only allowed via interactive form.

Comments
Sweeeeeet. Yeah, that is huge!
# Posted By Ben Nadel | 5/4/07 1:37 PM
WHoooOOOOP!!!

Give us some examples, PLEASE! (Of course I can wait till you are in Lansing, and you can show us that also.)
# Posted By John Farrar | 5/4/07 1:44 PM
My guess is it would work like this (sorry, I am toooo excited to wait for Ben to say anything ;)):

<cfset arrMatches = REMatch( TEXT, REG_EX, SCOPE ) />

<cfloop index="i" from="1" to="#ArrayLen( arrMatches )#">

Match #i#: #arrMatches[ i ]#

</cfloop>

From Ben's description, it looks like it might not have a SCOPE param, but I thought it would be cool.
# Posted By Ben Nadel | 5/4/07 1:48 PM
Give it an expression and a string and get back an array of matches. Like this:

<!--- Find all the URLs in a web page retrieved via CFHTTP --->
<cfset result = REMatch("https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?", CFHTTP.FileContent)>

--- Ben
# Posted By Ben Forta | 5/4/07 1:54 PM
Oh cool, so it's more like REFind() rather than REReplace().

This is totally exciting. I can't wait to see all this in NYC later this month.
# Posted By Ben Nadel | 5/4/07 2:20 PM
Ben, yes, similar to JavaScript's Match. Instead of having to do a REFind(), and then loop through the results extracting them all from start position for n chars, this does all the work for you.

--- Ben
# Posted By Ben Forta | 5/4/07 2:27 PM
Genius! This might be my favorite new feature. Hell, it might be my favorite new feature ever introduced. Well, other than CFDUMP. That was beyond genius and will never be surpassed.
# Posted By Rob Wilkerson | 5/4/07 5:33 PM
https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)? Doesn't work with dashes

eg
http://www.abc.com/g/xxx-yyy-zzz/123456/v_content/1.jpg" target="_blank">http://www.abc.com/g/xxx-yyy-zzz/123456/v_content/...

result
http://www.abc.com/g/xxx
# Posted By Terry M | 11/9/07 10:05 PM
Hi Ben,
You said "Over the years several of us have written our own functions to do this, but that's no longer needed", can you give me an example or point me to one that I could reference? I created a string manipulation for CF8, but now need to build back to CF MX 6.1. I am having trouble with performance in all my trials, so any help would be greatly appreciated!

The script takes 3 seconds in CF8, but when I try to use a different script in CF MX 6.1, it takes alsom 50 seconds. The string input length varies, so I need good performance.

Thanks,
Dan
# Posted By Dan Arsenault | 4/14/08 12:13 PM
I've been struggling with using rematch to add 'target=_blank"' to <a> tags in a string. Can anyone help with the expression?
# Posted By Duane Hardy | 6/11/08 10:43 AM

  © Copyright 1997-2008 Ben Forta, All Rights Reserved