• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

18. Regular Expressions in ColdFusion > 18.3. Replacing Strings

Replacing Strings

String replacement is performed with the REReplace( ) and REReplaceNoCase( ) functions. REReplace( ) performs case-sensitive search and replace functions, while REReplaceNoCase( ) is used for case-insensitive search and replace. Regardless of which tag you use, they have the same syntax:

REReplace(String, RegularExpression, Substring [, Scope])
REReplaceNoCase(String, RegularExpression, Substring [, Scope])

Both functions take three required parameters and one optional parameter. The first required parameter is the string to perform the regular expression on. The string can be either a block of text enclosed in single or double quotes or a variable that contains the text that you want to search. The second required parameter is the regular expression you want to use for your search. Any valid ColdFusion regular expression can be used. The third required parameter is the substring. The substring contains the string to replace any matches made by the regular expression. The final parameter is optional and determines the scope of the search-and-replace operation. The scope can be set to One or All. Setting the scope to One (the default) replaces only the first occurrence of the substring; setting it to All replaces all occurrences of the substring. The following two examples show the use of the REReplace( ) and REReplaceNoCase( ) functions:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint