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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson