FME Transformers: 2025.2 BETA

Categories
Strings
Related Transformers
StringSearcher

StringReplacer

Replaces substrings matching text or patterns described by regular expressions.  

Jump to Configuration

Typical Uses

  • Editing strings based on text or pattern matching

How does it work?

The StringReplacer receives features with attributes and replaces portions of attribute values (substrings) with new text.

Replacement can be done either by matching a specific string or by using regular expressions to specify string patterns. Matching may be case-sensitive or not.

Multiple replacements can be performed in a single StringReplacer. They are executed sequentially, and so can operate on earlier replacements done in the same transformer.

Matching Text

When Mode is Replace Text, the input string is matched exactly (with the option of case-sensitivity) and replaced.

Input

Text to Replace

Replacement Text

Output

Bobby

obb

ill

Billy

Matching Regular Expressions

When Mode is Replace Regular Expression, input strings are evaluated against a regular expression.

Input

Text to Replace

Replacement Text

Output

Look_cows

o{2}

88

L88k_cows

Regular expressions can be created and tested in the Regular Expression Editor, accessible via the Text to Replace context menu.

Special characters and sequences are used, some of which are listed here:

Special Character Description
| Separates branches (choices)
* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
. Matches any single character
^ Matches the start of the value
$ Matches the end of the value
[ ] Enclose a set of character choices
( ) Enclose a "subexpression"

Advanced Regular Expressions (AREs) are supported. AREs have one or more branches, separated by |, matching any of the branches.

Note  For full information on syntax, special characters, and more, see Perldoc - Regular Expressions.

Using Match Groups

Match groups are created when sub-parts exist in the expression, enclosed in parentheses. Each part captures a sub-match from the input text.

These parts can be referred to in the Replacement Text by a backslash followed by the number of the part - \2 refers to the contents matching the second set of parentheses.

In this example, the expression describes a pattern of a word, then a space, then a second word. The words are enclosed in parentheses, and so can be used as a match group.

In the StringReplacer, it could be used like this:

Input

Text to Replace

Replacement Text

Output

First Second

(\w+)\s(\w+)

\2 \1

Second First

Usage Notes

  • See the StringSearcher transformer help for additional regular expression examples.
  • To search for regular expression matches in a string without doing any replacement, use the StringSearcher transformer.

Configuration

Input Ports

Output Ports

Parameters

Editing Transformer Parameters

Transformer parameters can be set by directly entering values, using expressions, or referencing other elements in the workspace such as attribute values or user parameters. Various editors and context menus are available to assist. To see what is available, click beside the applicable parameter.

For more information, see Transformer Parameter Menu Options.

Reference

Processing Behavior

Feature-Based

Feature Holding

No

Dependencies None
Aliases  
History  

FME Online Resources

The FME Community and Support Center Knowledge Base have a wealth of information, including active forums with 35,000+ members and thousands of articles.

Search for all results about the StringReplacer on the FME Community.

 

Examples may contain information licensed under the Open Government Licence – Vancouver, Open Government Licence - British Columbia, and/or Open Government Licence – Canada.