bulk_search_and_replace
Performs a bulk search and replace on a string using a list of records. Each record provides a search value and its corresponding replacement. A search condition determines whether any replacements are attempted.
Syntax
bulk_search_and_replace(s, record_list, search_condition, search_field, replace_field)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| s | string | Yes | The input string to perform replacements on. |
| record_list | list[Record] | Yes | A list of records containing search and replacement values. |
| search_condition | string | Yes | A string that must exist in the input string for any replacements to occur. If the condition is not found, the input is returned unchanged. |
| search_field | string | Yes | The field name on each record containing the value to search for. |
| replace_field | string | Yes | The field name on each record containing the replacement value. |
Returns
Type: string
The input string with all matching replacements applied, or the original string if the search condition is not met.
Examples
Replace user IDs with display names using a lookup table:
bulk_search_and_replace([comment_body], [user_records], "@", "user_id", "display_name")
Only performs replacements if the comment body contains "@". For each record in user_records, replaces the user_id value with the display_name value.
Substitute category codes with labels:
bulk_search_and_replace([raw_data], [category_map], "CAT-", "code", "label")
If raw_data contains "CAT-", each category code found in the mapping records is replaced with its label.
Notes
- The search condition is checked first. If the condition string is not found in the input, the function returns the original string without iterating through the record list. This provides a performance optimization for large record lists.
- Replacements are applied sequentially in the order of the record list. A replacement made by an earlier record could be affected by a later record's search pattern.
- All items in the record list must be Record instances.
Comments
0 comments
Please sign in to leave a comment.