Spec-Zone.ru › ColdFusion

reReplace

Uses a regular expression (regex) to search a string for a string pattern and replace it with another. The search is case-sensitive.

reReplace(string, regex, substring [, scope]) → returns string

Member Function Syntax

string.reReplace(regex, substring[, scope])

  • CF
  • Lucee
  • BL 1.0.0+
  • See Also: rereplacenocase refind refindnocase replace rematch rematchnocase

    Argument Reference

    string string
    Required

    A string or a variable that contains one

    regex string
    Required

    Regular expression to replace.

    substring string
    Required

    A string or a variable that contains one. Replaces substring with the regex match

    scope string
    Default: one

    * one: Replace the first occurrence of the regular expression. Default. * all: Replace all occurrences of the regular expression.
    Values:
    • one
    • all

    Links more information about reReplace

    • Regular Expressions in ColdFusion Howto - Learn about regex in CFML, written by Pete Freitag
    • Regular Expression Cheat Sheet - Lists the special characters and their meanings

    Examples
    Sample code invoking the reReplace function

    Strip Characters Using reReplace

    This example strips out all characters except a-z and 0-9.

    reReplace("test 123!", "[^a-z0-9]", "", "ALL")

    Expected Result: test123

    Extract Characters Using Back Reference

    Uses a back reference: \1 to extract the pattern contained within the parenthesis.

    reReplace("123abc456", "[0-9]+([a-z]+)[0-9]+", "\1")

    Expected Result: abc

    © 2012–present Foundeo, Inc. and the CFDocs contributors.
    Licensed under the MIT License.
    ColdFusion is a trademark of Adobe Systems Incorporated.
    https://cfdocs.org/rereplace

    Spec-Zone.ru

    Настройки Оффлайн Что нового Помощь О нас
    Spec-Zone .ru
    спецификации, руководства, описания, API