Match characters · match_characters

🟢 4 of 4 forms all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc2 (90ee9376) · pandas 2.3.3 · DuckDB 1.5.5
🟢 all ok🟡 partially implemented🛡️ refused with an error🔴 not implemented or crash🔵 engines differ ✅ match · ❌ wrong result · 🛡 guarded error (code) · 💥 crash · 📌 team decision
Dataset formsComponent formsScalar forms
        ---
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
Clause operators (9) 🟢9
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 of DS_1 against a pattern.

Manual:

Match characters, Example 1, output verbatim: “match_characters returns true if op matches the regular expression regexp, false otherwise.”

Expected:

bool_var is true for G (AX123) and false for R (AX2J5).

script.vtl
DS_r:=match_characters(DS_1, "[A-Za-z]{2}[0-9]{3}");
Input DS_1
Id_1Id_2Id_3Id_4Me_1
GTotalPercentageTotalAX123
RTotalPercentageTotalAX2J5
Expected DS_r
Id_1Id_2Id_3Id_4bool_var
GTotalPercentageTotaltrue
RTotalPercentageTotalfalse

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}") inside calc: 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_2 is a new boolean measure: true for AX123, false for AX2J5, which has no two letters followed by three digits, true for QZ987 and null for the null; Me_1 is 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).

script.vtl
DS_r := DS_1 [ calc Me_2 := match_characters(Me_1, "[A-Za-z]{2}[0-9]{3}") ];
Input DS_1
Id_1Me_1
1AX123
2AX2J5
3QZ987
4
Expected DS_r
Id_1Me_1Me_2
1AX123true
2AX2J5false
3QZ987true
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) inside calc: the pattern is the component Me_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_3 is a new boolean measure: true for AX123, false for AX2J5, true for 123 against its own pattern [0-9]+, and null for the null; Me_1 and Me_2 are 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).

script.vtl
DS_r := DS_1 [ calc Me_3 := match_characters(Me_1, Me_2) ];
Input DS_1
Id_1Me_1Me_2
1AX123[A-Z]{2}[0-9]{3}
2AX2J5[A-Z]{2}[0-9]{3}
3123[0-9]+
4[0-9]+
Expected DS_r
Id_1Me_1Me_2Me_3
1AX123[A-Z]{2}[0-9]{3}true
2AX2J5[A-Z]{2}[0-9]{3}false
3123[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) with SC_1 = "AX123" and SC_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: AX123 is two letters followed by three digits.

script.vtl
SC_r := match_characters(SC_1, SC_2);
Input scalars
SC_1SC_2
AX123[A-Za-z]{2}[0-9]{3}
Expected scalars

Name

Type

Value

SC_r

Boolean

true

Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗