| Contents > Developing ColdFusion MX Applications > Using Regular Expressions in Functions > Using backreferences > Omitting subexpressions from backreferences |
|
|
|
|
||
By default, a set of parentheses will both group the subexpression and capture its matched text for later referral by backreferences. However, if you insert "?:" as the first characters of the subexpression, ColdFusion performs all operations on the subexpression except that it will not capture the corresponding text for use with a back reference.
This is useful when alternating over subexpressions containing differing numbers of groups would complicate backreference numbering. For example, consider an expression to insert a "Mr." in between Bonjour|Hi|Hello and Bond, using a nested group for alternating between Hi & Hello:
<cfset regex = "(Bonjour|H(?:i|ello))( Bond)"> <cfset replaceString = "\1 Mr.\2"> <cfset string = "Hello Bond"> #reReplace(string, regex, replaceString)#
This example returns "Hello Mr. Bond". If you did not prohibit the capturing of the Hi/Hello group, the \2 backreference would end up referring to that group instead of " Bond", and the result would be "Hello Mr.ello".
|
|
||
| Contents > Developing ColdFusion MX Applications > Using Regular Expressions in Functions > Using backreferences > Omitting subexpressions from backreferences |
|
|
ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting
Version 6.1
Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/regexp18.htm