Captures a value from an existing field using regex and inserts the matching groups in newly created field(s). By default the original field is omitted and if there is no match for the regex an error is thrown.
Example
dim_A | dim_B | metric_1 |
AAA_aaa | DDD | 111 |
BBB_111 | EEE | 222 |
CCCccc | FFF | 333 |
dim_A | dim_B | metric_1 | dim_new_1 | dim_new_2 |
AAA_aaa | DDD | 111 | AAA | aaa |
BBB_111 | EEE | 222 | BBB | empty |
CCCccc | FFF | 333 | my_value | empty |
I Ain't Afraid of No Code!
[
[
"capture",
{
"include_original": true,
"subtable": null,
"fill": [
"my_value",
"empty"
],
"newfields": [
"dim_new_1",
"dim_new_2"
],
"field": "dim_A",
"pattern": "(.*)_(\\w+)",
"_comment": null
}
]
]
param boolean include_original: Retain source_field. Defaults to false.
param str subtable: Name a subtable in which output will be stored (will create subtable where necessary).
param str fill: Provide a list or tuple of values to use in case Regex doesn’t match. Should contain exact amount of values as there are capturing groups in RegEx. Defaults to None and will raise a “petl.transform.TransformError” on the first non-matching value.
param list newfields: Newly created fields in which contents of matching groups are parsed. Requires one result field per matching group.
param str field: Initial field on which Regex is performed.
param str pattern: Regex with n capturing groups to match field.
param str comment: A comment that will appear in the Transformation UI.
Comments
0 comments
Article is closed for comments.