Match characters · match_characters
---
config:
flowchart:
useMaxWidth: false
---
flowchart TB
classDef ok fill:#d4edda,stroke:#28a745,color:#000
classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
O["Match characters · match_characters<br/>🟢4"]:::ok
subgraph G_ds["Dataset"]
direction LR
v_ds_sc["match_characters(DS, sc)"]:::ok
end
subgraph G_comp["Component"]
direction LR
v_comp_sc["match_characters(comp, sc)"]:::ok
v_comp_comp["match_characters(comp, comp)"]:::ok
end
subgraph G_sc["Scalar"]
direction LR
v_sc_sc["match_characters(sc, sc)"]:::ok
end
O --- G_ds
O --- G_comp
O --- G_sc
style G_ds fill:#f8f9fa,stroke:#495057,stroke-width:2px
style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
style G_sc fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 2 3
click v_ds_sc href "#form-ds-sc"
click v_comp_sc href "#form-comp-sc"
click v_comp_comp href "#form-comp-comp"
click v_sc_sc href "#form-sc-sc"
Types
Takes string · Gives boolean
Comes from · string — 13 operators in 3 blocks 🟢13
General purpose operators (2) 🟢2
String operators (8) 🟢8
Data validation operators (3) 🟢3
Comes from · operators that return any type (their input's) — 37 operators in 8 blocks 🟢37
General purpose operators (5) 🟢5
Join operators (4) 🟢4
Time operators (3) 🟢3
Set operators (4) 🟢4
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Conditional operators (3) 🟢3
Goes to · boolean — 27 operators in 8 blocks 🟢27
General purpose operators (1) 🟢1
Join operators (4) 🟢4
Boolean operators (4) 🟢4
Aggregate and Analytic operators (10) 🟢10
Data validation operators (1) 🟢1
Conditional operators (2) 🟢2
Clause operators (2) 🟢2
Definitions (VTL-DL) (3) 🟢3
Goes to · operators that take any scalar — 38 operators in 8 blocks 🟢38
General purpose operators (6) 🟢6
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (7) 🟢7
Data validation operators (1) 🟢1
Conditional operators (1) 🟢1
Clause operators (7) 🟢7
Definitions (VTL-DL) (1) 🟢1
Forms
match_characters(DS, sc) 🟢 · string → boolean
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
match_characters(DS_1, "[A-Za-z]{2}[0-9]{3}"): the string measure ofDS_1against a pattern.- Manual:
Match characters, Example 1, output verbatim: “match_characters returns true if op matches the regular expression regexp, false otherwise.”
- Expected:
bool_varis true for G (AX123) and false for R (AX2J5).
DS_r:=match_characters(DS_1, "[A-Za-z]{2}[0-9]{3}");
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| G | Total | Percentage | Total | AX123 |
| R | Total | Percentage | Total | AX2J5 |
| Id_1 | Id_2 | Id_3 | Id_4 | bool_var |
|---|---|---|---|---|
| G | Total | Percentage | Total | true |
| R | Total | Percentage | Total | false |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
match_characters(comp, sc) 🟢 · string → boolean
Matches and null operand 🟢 pandas ✅ · DuckDB ✅
- Tests:
match_characters(Me_1, "[A-Za-z]{2}[0-9]{3}")insidecalc: two letters followed by three digits; two values match, one does not and one is null.- Manual:
Match characters: “match_characters returns true if op matches the regular expression regexp, false otherwise.” The pattern is “an Extended Regular Expression as described in the POSIX standard”, and the page warns that implementations “may behave in slightly different ways”: each string here matches in full or has no match at all, so matching the whole string and searching inside it agree.
- Expected:
Me_2is a new boolean measure: true forAX123, false forAX2J5, which has no two letters followed by three digits, true forQZ987and null for the null;Me_1is kept. A null operand gives a null result: “most of the scalar operations (arithmetic, logical, and others) return null when any of their arguments is null” (User Manual).
DS_r := DS_1 [ calc Me_2 := match_characters(Me_1, "[A-Za-z]{2}[0-9]{3}") ];
| Id_1 | Me_1 |
|---|---|
| 1 | AX123 |
| 2 | AX2J5 |
| 3 | QZ987 |
| 4 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | AX123 | true |
| 2 | AX2J5 | false |
| 3 | QZ987 | true |
| 4 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
match_characters(comp, comp) 🟢 · string → boolean
Pattern from a component and null 🟢 pandas ✅ · DuckDB ✅
- Tests:
match_characters(Me_1, Me_2)insidecalc: the pattern is the componentMe_2, which differs between data points, and the operand is null in one.- Manual:
Match characters: “match_characters returns true if op matches the regular expression regexp, false otherwise.” The pattern is “an Extended Regular Expression as described in the POSIX standard”, and the page warns that implementations “may behave in slightly different ways”: each string here matches in full or has no match at all, so matching the whole string and searching inside it agree.
- Expected:
Me_3is a new boolean measure: true forAX123, false forAX2J5, true for123against its own pattern[0-9]+, and null for the null;Me_1andMe_2are kept. A null operand gives a null result: “most of the scalar operations (arithmetic, logical, and others) return null when any of their arguments is null” (User Manual).
DS_r := DS_1 [ calc Me_3 := match_characters(Me_1, Me_2) ];
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | AX123 | [A-Z]{2}[0-9]{3} |
| 2 | AX2J5 | [A-Z]{2}[0-9]{3} |
| 3 | 123 | [0-9]+ |
| 4 | [0-9]+ |
| Id_1 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|
| 1 | AX123 | [A-Z]{2}[0-9]{3} | true |
| 2 | AX2J5 | [A-Z]{2}[0-9]{3} | false |
| 3 | 123 | [0-9]+ | true |
| 4 | [0-9]+ |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
match_characters(sc, sc) 🟢 · string → boolean
Matching string 🟢 pandas ✅ · DuckDB ✅
- Tests:
match_characters(SC_1, SC_2)withSC_1="AX123"andSC_2="[A-Za-z]{2}[0-9]{3}": a string that matches a pattern of two letters and three digits.- Manual:
Match characters: “match_characters returns true if op matches the regular expression regexp, false otherwise.” The pattern is “an Extended Regular Expression as described in the POSIX standard”, and the page warns that implementations “may behave in slightly different ways”: each string here matches in full or has no match at all, so matching the whole string and searching inside it agree.
- Expected:
SC_r = true, a Boolean:AX123is two letters followed by three digits.
SC_r := match_characters(SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| AX123 | [A-Za-z]{2}[0-9]{3} |
Name |
Type |
Value |
|---|---|---|
|
Boolean |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗