CFLib.org – Common Function Library Project

reCompile([flags])

Last updated May 30, 2011

author

Henry Ho

Version: 1 | Requires: CF9 | Library: StrLib

Description:
Create a java.util.regex.Pattern in a CF-friendly way. Returns an instance of java.util.regex.Pattern. flags - List or Array of: 'CANON_EQ', 'CASE_INSENSITIVE', 'COMMENTS', 'DOTALL', 'LITERAL', 'MULTILINE', 'UNICODE_CASE', 'UNIX_LINES'

Return Values:
Returns a Java object.

Example:

<cfscript>
pattern = reCompile("a*b");

m = pattern.matcher("aaaaab");

writeDump(m.matches());

</cfscript>

Parameters:

Name Description Required
flags List or an array of valid Java Regex pattern flags: 'CANON_EQ', 'CASE_INSENSITIVE', 'COMMENTS', 'DOTALL', 'LITERAL', 'MULTILINE', 'UNICODE_CASE', 'UNIX_LINES' No

Full UDF Source:

/**
 * Create a java.util.regex.Pattern in a CF-friendly way.
 * 
 * @param flags      List or an array of valid Java Regex pattern flags: 'CANON_EQ', 'CASE_INSENSITIVE', 'COMMENTS', 'DOTALL', 'LITERAL', 'MULTILINE', 'UNICODE_CASE', 'UNIX_LINES' (Optional)
 * @return Returns a Java object. 
 * @author Henry Ho (henryho167@gmail.com) 
 * @version 1, May 30, 2011 
 */
function reCompile(required String regex, flags) {
    var pattern = createObject("java","java.util.regex.Pattern");
        
    if (isNull(flags))
        local.compiled = pattern.compile(regex);
    else {
        if (isSimpleValue(flags))
            flags = listToArray(flags);
    
        var flagInt = 0;
            
        for (local.flagName in flags)
            flagInt += pattern[flagName];
            
        local.compiled = pattern.compile(regex, javacast("int", flagInt));
    }
        
    return local.compiled;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson