← match_characters operator page · comparison/match_characters/ds_sc/manual_ex_1

Manual example 1 🟢 all ok

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.csv ⇩

Id_1Id_2Id_3Id_4Me_1
GTotalPercentageTotalAX123
RTotalPercentageTotalAX2J5

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Id_2", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Id_3", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Id_4", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "String", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Id_2Id_3Id_4bool_var
GTotalPercentageTotaltrue
RTotalPercentageTotalfalse

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "String", "role": "Identifier"},
        {"name": "Id_2", "type": "String", "role": "Identifier"},
        {"name": "Id_3", "type": "String", "role": "Identifier"},
        {"name": "Id_4", "type": "String", "role": "Identifier"},
        {"name": "bool_var", "type": "Boolean", "role": "Measure"}
      ]
    }
  ]
}