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 thoughts

  1. 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 ]#
    From Ben’s description, it looks like it might not have a SCOPE param, but I thought it would be cool.

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

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

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

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

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