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

17.4. Back References

Back references allow your regular expressions to refer to previously matched subexpressions. This is useful in situations where you want your regular expression to use a match as part of the criteria for an additional regular-expression function. A commonly used scenario to illustrate back referencing involves using a regular expression to remove doubled words within a sentence. For example, suppose you have the string "I would like to go to to the park." The word "to" appears twice in a row—a common typing mistake. The regular expression to remove any doubled words from the sentence looks like this:

<CFSET NoDupes = ReReplaceNoCase("I would like to go to to the park.", 
"([A-Z]+)[ ]+\1", "\1", "All")>


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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