Regular expressions and patterns in field normalization rules
Summarize
Summary of Regular Expressions and Patterns in Field Normalization Rules
This document explains how to utilize regular expressions (regex) and pattern matching within field normalization rules in ServiceNow. Regular expressions allow for precise character manipulation in field values, enabling efficient data transformation based on defined patterns.
Show less
Key Features
- Regex Utilization: Regular expressions can be employed in transform parameters and condition statements to specify which characters should be transformed.
- Syntax: Regex patterns must start with /regex/ to indicate their function in locating characters within field values.
- Pattern Matching: The platform supports unique special characters for pattern matching, which differ from regex syntax.
Key Outcomes
By implementing regular expressions in your field transformations, you can:
- Simplify data entries, such as removing unnecessary prefixes (e.g., domain names) from computer names.
- Utilize the Replace Transform Type to redefine field values based on specific criteria.
- Test and apply transformations to existing records efficiently through the Transformation application data job.
For example, an administrator can transform a computer name from "development\devlab01" to "devlab01" by targeting the backslash and utilizing regex to extract the desired machine name.
Field Transformation definitions support the use of regular expressions (referred to in the platform as regex) and pattern matching for determining the position of characters in a string.
After identifying the target characters, field transformation can replace or delete the identified characters or insert other characters at that position.
Regex
Regular expressions can be used in transform parameters and in condition statements to determine which characters in a field value are transformed.
Regular expressions used as parameters to locate characters in transformed field values must begin with /regex/. Everything after that is a regular expression that is used to calculate character position.
Example
- Find:/regex/.*\\(.*)
- Replace with:$1
The regular expression .*\\(.*) represents the entire raw value in the Name field - in this example development\devlab01. The first part of the expression, .*, represents everything before the backslash (the development domain name). The backslash by itself is the escape character in regular expressions and requires special syntax to retain its function in the computer name. The administrator must escape it by using another backslash (\\ means \). The part of the expression after the backslash, (.*), represents the computer name (devlab01) and is grouped within parentheses for reference. The value in the Replace with field, $1, references this group and replaces the entire raw value of the field with the contents of the group, devlab01.
When the transforms for this field are tested successfully, the administrator changes the Mode in the transformation record to Active and runs the Transformation application data job to apply this transformation to existing records in the database.