AdobeStock_455007340

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.

10 responses to “Scorpio Adds Two New RegEx Functions”

  1. Ben Nadel Avatar
    Ben Nadel

    Sweeeeeet. Yeah, that is huge!

  2. John Farrar Avatar
    John Farrar

    WHoooOOOOP!!!
    Give us some examples, PLEASE! (Of course I can wait till you are in Lansing, and you can show us that also.)

  3. Ben Nadel Avatar
    Ben Nadel

    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.

  4. Ben Forta Avatar
    Ben Forta

    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

  5. Ben Nadel Avatar
    Ben Nadel

    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.

  6. Ben Forta Avatar
    Ben Forta

    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

  7. Rob Wilkerson Avatar
    Rob Wilkerson

    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.

  8. Terry M Avatar
    Terry M

    https?://([-w.]+)+(:d+)?(/([w/_.]*(?S+)?)?)? Doesn’t work with dashes
    eg
    http://www.abc.com/g/xxx-yyy-zzz/123456/v_content/1.jpg
    result
    http://www.abc.com/g/xxx

  9. Dan Arsenault Avatar
    Dan Arsenault

    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

  10. Duane Hardy Avatar
    Duane Hardy

    I’ve been struggling with using rematch to add ‘target=_blank"’ to <a> tags in a string. Can anyone help with the expression?

Leave a Reply

Discover more from Ben Forta

Subscribe now to keep reading and get access to the full archive.

Continue reading