<cfscript> input = " I like to move it, move it. You like to move it, move it. We like to move it, move it. "; writeDump([ "move it": reCountOccurrences( input, "move it" ), "(move it), \1": reCountOccurrences( input, "(move it), \1" ), "like.to": reCountOccurrences( input, "like.to" ) ]); // ------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------- // /** * I count the number of occurrences of the given regular expression pattern within the * target string using a case-sensitive search. */ private numeric function reCountOccurrences( required string target, required string pattern ) { var matcher = createObject( "java", "java.util.regex.Pattern" ) .compile( pattern ) .matcher( target ) ; var count = 0; while ( matcher.find() ) { count++; } return count; } </cfscript>