If you want more than a simple string replacement with common regular expressions you certainly run into trouble and hit the wall when discovering the limits of the regex functions Coldfusion has. There is no build-in function like php's
|The regular expression|
|The string which should be applyed the the regex|
|The function where the captured grouped will be passed in if a match was found. There the matches can be processed|
Because Coldfusion itself does not offer what we want, we make recourse to the variety of Java, which is — as we all know — on top of Coldfusion. Java offers us
So here is what we actually do:
Compilemethod from the
PatternClass object and passing the regex pattern to it (which probably deposits the regex pattern for later use).
Matchermethod on what the
Compilemethod returned and passing the string where the pattern should be executed.
findmethod on what the
true, we could say "That's it", but there is one little thing we have to consider: Java's Pattern object stores the groups and gives us access via another function, which is not always the best way for further processing and not that consistent regarding how other programming languages handle this case. Therefore we loop over
matcher.group() so that we can pass an array containing the captured groups to the callback function. And now we can say: "That's it!"