Filter Symbols using Wildcards?
Joe Kaplan
5月 25 2020 | 10:02 午後
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
5月 25 2020 | 11:18 午後
[regex]
Joe Kaplan
5月 26 2020 | 12:43 午前
just what I needed. Thanks!
Joe Kaplan
5月 26 2020 | 1:59 午前
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
9月 08 2024 | 2:51 午後
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.
Explanation:
List sent to [t b l]
List is output to [zl.queue], who stores it.
[zl.queue] sends number of items in the list (N) to [uzi]
Bang is sent to [uzi], who emits N bangs to [zl.queue]
[zl.queue] emits each item to [regexp]
Matching items emitted from [regexp] outlet 3
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.)[zl.group] collects each item
[uzi] emits a bang from outlet 2 when it is finished, which is connected to [zl.group] which emits the stored list.
...
Profit!
Zack Steinkamp
9月 08 2024 | 2:54 午後
Simplified with [iter] which can replace the [zl.queue] and [uzi] combo.
Roman Thilenius
9月 09 2024 | 3:24 午前
making a regexp gate/router dynamic...
...though after 4096 queries you´d probably have to re(script-)create the [regexp] object.
TFL
9月 09 2024 | 1:12 午後
though after 4096 queries you´d probably have to re(script-)create the [regexp] object.
Why that?