Choose Language Hide Translation Bar
Community Trekker

Searching data table for non exact matches?

I'm working on a script where I have a variable "Plate" that is set as text like "8SVPCCV1G0BB2".  I need to use this variable to select a row in a different table where "Plate" may be wildcarded like:





In this case I would want it to select the row 8SV.  But if my variable was "8PSVTTY2G0AB3" I would want it to match the * row which is a generic row.

I was looking into using regex or pattern matching for this but I'm new to both of them so I'm not having luck yet.  Am I on the right track looking at those?  Or is there a better way to do this matching?  Thanks!

0 Kudos
Community Trekker

Re: Searching data table for non exact matches?

I was able to get this to work if there is a matching line:

targetconfig << New Column ("PlateMatch", Formula(Pat Match(plate , :PlateStart)));

The only problem with this is if the plate only matches the * line.

0 Kudos
Super User ms
Super User

Re: Searching data table for non exact matches?

I'm sure there are several ways to approach this. One way is to first try to select the rows that match the pattern, and if no rows are selected it selects the "*" row.

// Example table

my_table = Open("$SAMPLE_DATA/Big");

:name[1] = "*";

// Function for selecting matching row(s)or default row "*"

select_plate = Function({dt, p},

    dt << select where(Pat Match(:name, plate));

    If(N Row(dt << getselected rows) == 0,

        dt << select where(:name == "*")



// Test the function

plate = "ACL";

select_plate(my_table, plate);


plate = "QQQ";

select_plate(my_table, plate);

0 Kudos