Subscribe Bookmark RSS Feed

Searching data table for non exact matches?

ejyoung

Community Trekker

Joined:

Jul 18, 2016

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:

8S

8SV

8SQPCC

*

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!

2 REPLIES
ejyoung

Community Trekker

Joined:

Jul 18, 2016

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.

ms

Super User

Joined:

Jun 23, 2011

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 Class.jmp");

: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);

Wait(2);

plate = "QQQ";

select_plate(my_table, plate);