Regular expressions and patterns in field normalization rules
Summarize
Summary of Regular expressions and patterns in field normalization rules
The Field Transformation feature in ServiceNow enables the use of regular expressions (regex) and pattern matching to manipulate character positions within strings. This allows for the replacement, deletion, or insertion of characters in field values based on defined patterns.
Show less
Key Features
- Regular Expressions: Regex can be utilized in transformation parameters and condition statements to identify specific characters for transformation. It is essential that regex patterns begin with /regex/.
- Pattern Matching: This method employs special characters to create recognizable patterns for field value transformations, differing from regex in its syntax and application.
Key Outcomes
For instance, a network administrator can simplify computer names by removing the domain prefix from a string formatted as domain\machine name. By applying a regex transformation, they can effectively isolate and retain only the machine name, enhancing data clarity. Once the transformation is tested successfully, it can be activated and applied to existing records in the database, streamlining the data management process.
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.