Filter Symbols using Wildcards?

Joe Kaplan's icon

Say I have a list of symbolls, and some of them are similar: sym1, sym2, sym3, sym4, sym4b, notsym1, notsym2, notsym3, etc.

Is there a way to filter the list according to wildcards. I'm looking for something I can give an argument like "sym*" and get all the list items that begin with "sym," while excluding all the ones that don't begin with those three characters.

Sprintf can combine components into a single symbol. I'm looking for something that can analyze components of a single symbol and output accordingly.

all the zl stuff appears to operate at the granularity of the symbol itself. It looks like [zl compare] and [zl filter] require an exact match of the symbol. I want to use those functions on part of the symbol.

I suppose I could do it using js. But i was curious if Max offered anything natively that can do this.

DK's icon

[regex]

Joe Kaplan's icon

just what I needed. Thanks!

Joe Kaplan's icon

Playing [regex] now. I see that I can output the part of the symbol that matches the expression I give, but I don't see how I can output the WHOLE symbol if part of it matches the expression.

I guess I need to use the third Outlet to drive some sort of gating mechanism that determines whether the original string continues on in the flow? Or is there some simpler way to do it with just [regex]?

Zack Steinkamp's icon

I encountered this problem today. [regex] is a component of the solution. In my case I was looking to exclude items from the list based on a regexp match, but this technique can be used to only include matching elements by connecting the [zl.group] to [regex] outlet 3 instead of 4.

Max Patch
Copy patch and select New From Clipboard in Max.

Explanation:

  1. List sent to [t b l]

    1. List is output to [zl.queue], who stores it.

      1. [zl.queue] sends number of items in the list (N) to [uzi]

    2. Bang is sent to [uzi], who emits N bangs to [zl.queue]

      1. [zl.queue] emits each item to [regexp]

        1. Matching items emitted from [regexp] outlet 3

        2. Unmatched items emitted from [regexp] outlet 4.
          (In the example, outlet 4 is connected to [zl.group]. Connect [zl.group] to outlet 3 if you want to include matches instead of excluding matches.)

          1. [zl.group] collects each item

      2. [uzi] emits a bang from outlet 2 when it is finished, which is connected to [zl.group] which emits the stored list.

      3. ...

      4. Profit!

Zack Steinkamp's icon

Simplified with [iter] which can replace the [zl.queue] and [uzi] combo.

Max Patch
Copy patch and select New From Clipboard in Max.

Roman Thilenius's icon

making a regexp gate/router dynamic...

...for search strings which may contain up to 8 space characters (useful when dealing with filenames or paths)...

...though after 4096 queries you´d probably have to re(script-)create the [regexp] object.

TFL's icon

though after 4096 queries you´d probably have to re(script-)create the [regexp] object.

Why that?