Skip to main content
Transformation: Replace

Use the Replace transformation to find and replace values in a column, with options for exact matches or regex patterns.

Quin Eddy avatar
Written by Quin Eddy
Updated this week

The Replace transformation in Nexadata Pipelines allows you to find and replace values within a specific column, with options for exact matching or using regular expressions for advanced pattern matching. This transformation is useful for correcting data, standardizing text, or updating values to align with a specific format or nomenclature. You can configure the transformation using Natural Language Mode or Advanced Mode, depending on the level of control required.


Inputs for the Replace Transformation

  1. Name of the Transformation: In Natural Language Mode, the transformation name is automatically generated, but you can update it later in Advanced Mode. For example, you might rename it to "Standardize Location Names" or "Replace Outdated Titles".

  2. Column to Perform Find and Replace: Choose the column where the find and replace operation will be applied. For example, you may select "Department_Name", "Location", or "Status".

  3. Replace Type: Choose the type of replace operation:

    • Exact Match: Finds values that exactly match the specified find value.

    • Regular Expression: Uses a regular expression to identify patterns in the data for more flexible find-and-replace operations.

  4. Find Value: Enter the value or pattern you want to locate within the selected column. This could be a specific word, phrase, or pattern if using regular expressions.

  5. Replace Value: Enter the value that will replace each match found in the selected column. This could be a standard name, updated text, or a reformatted string.


Using Natural Language Mode

In Natural Language Mode, describe the replacement you want to perform, and Nexadata will automatically configure the transformation. The transformation name is auto-generated but can be modified later in Advanced Mode.

Example Instructions in Natural Language Mode:

  • Replace all instances of “NY” in Location column with “New York.”

  • Find and replace “Inactive” with “Former” in the Status column.

  • Replace abbreviations in Department_Name with full names using regular expressions.

  • Replace “Temp” with “Temporary” in Job_Title.

  • In Employee_Status, replace “Term” with “Terminated.”

Note: If Natural Language Mode doesn’t fully capture your requirements, you can switch to Advanced Mode for more control.


Using Advanced Mode

In Advanced Mode, you have complete control over the Replace transformation, allowing you to manually specify the column, replacement type, find value, and replace value. Advanced Mode allows for detailed control, ensuring the transformation precisely aligns with your analytical needs.

Steps in Advanced Mode

  1. Name of the Transformation: Enter or update a custom name, such as "Update Location Names" or "Replace Temporary Titles".

  2. Column to Perform Find and Replace: Select the column where you want the find-and-replace operation, such as "Location" or "Status".

  3. Replace Type: Choose the type of replace operation:

    • Exact Match for locating specific values.

    • Regular Expression for pattern-based replacements.

  4. Find Value: Specify the text or pattern to find within the selected column.

  5. Replace Value: Enter the new text that will replace each match found in the column.


Example Use Case: Standardizing Location Names

The Replace transformation is ideal for refining data by standardizing terms. For example, suppose your Location column contains abbreviations like "NY" and "LA", which you want to replace with full city names. For example:

  • Transformation Name: Standardize Location Names

  • Column to Perform Find and Replace: Location

  • Replace Type: Exact Match

  • Find Value: NY

  • Replace Value: New York

This configuration will replace each instance of "NY" in the Location column with "New York", improving consistency in the dataset.

Examples of Find and Replace Instructions:

  • Simple Exact Match

    • Description: Replace abbreviations in a column with full names.

    • Instruction: Replace "Mgr" with "Manager" in the Job_Title column.

  • Exact Match with Special Characters

    • Description: Replace numeric codes with text labels.

    • Instruction: Replace "1234" with "North Region" in the Region_Code column.

  • Regex Example with Capturing Groups

    • Description: Standardize names that may have middle initials.

    • Instruction: Replace names in the Full_Name column in the format (First M. Last) with First Last by removing the middle initial.

    • Regex: Find: (\w+)\s\w\.\s(\w+) Replace: $1 $2

  • Regex for Multiple Word Replacement (Greedy)

    • Description: Find and replace the longest substring between two words.

    • Instruction: Replace everything between "Begin" and "End" with "Section Content" in the Notes column.

    • Regex: Find: Begin.*End (Greedy) Replace: Section Content

  • Non-Greedy Regex with Optional Matches

    • Description: Capture the shortest substring between two markers.

    • Instruction: Replace text between "Start" and "Finish" with "Processed" in Comments.

    • Regex: Find: Start.*?Finish (Non-Greedy) Replace: Processed

  • Using Parentheses to Capture and Rearrange

    • Description: Reformat dates from MM-DD-YYYY to YYYY-MM-DD in the Date_Recorded column.

    • Instruction: Use regex to capture and rearrange date components.

    • Regex: Find: (\d{2})-(\d{2})-(\d{4}) Replace: $3-$1-$2

  • Complex Regex with Group Replacement

    • Description: Extract initials from names and place them in parentheses.

    • Instruction: Replace names in Employee_Name column in First Last format with First (L.).

    • Regex: Find: (\w+)\s(\w)\w+ Replace: $1 ($2.)

  • Partial Word Replacement with Regex

    • Description: Standardize department names containing "Fin" as "Finance".

    • Instruction: Replace "Fin" with "Finance" in the Department column.

    • Regex: Find: \bFin\b Replace: Finance

  • Pattern Matching with Non-Greedy Tag Extraction

    • Description: Remove any HTML tags, preserving only the inner text.

    • Instruction: Remove HTML tags in Description column.

    • Regex: Find: <.*?> (Non-Greedy) Replace: `` (empty string)

  • Capturing Repeating Patterns

    • Description: Standardize address abbreviations by capturing specific terms.

    • Instruction: Replace addresses in the format 123 Main St. to 123 Main Street in Address.

    • Regex: Find: (\bSt\.) Replace: Street


Summary

The Replace transformation in Nexadata Pipelines provides a powerful tool for find-and-replace operations, enabling you to update values within a column based on exact matches or regular expression patterns. Use Natural Language Mode for a quick setup or Advanced Mode for detailed control. This transformation is ideal for standardizing, correcting, or reformatting data within specific columns.

Did this answer your question?