Forums > MaxMSP

route partialmatch? / feature request

January 10, 2010 | 12:35 am

I’d like to be able to use a message like this in route:

[route playerblob%s]

that would route messages like:
playerblob01 or playerblobBall

Is there an object that does this?

I’m sure I could hack something together, but there must be a more efficient way…


January 10, 2010 | 1:40 am

the almighty regexp, at your service:

– Pasted Max Patch, click to expand. –

January 10, 2010 | 1:59 am

Thank you so much! Looks like I really need to get to know this object. I’ve kind of avoided it, because it is not so "plug and play".


January 10, 2010 | 2:10 am

not quite what I needed. I’d like it to work more like a route object. I guess i could use regexp to dynamically set a route, but maybe it is possible all in regexp? I don’t know perl and couldn’t find the answer in the help file. See attached patch to see what I am trying to do.

Thanks for the help.

– Pasted Max Patch, click to expand. –

January 10, 2010 | 3:34 am

You could try [regexp playerblob\w+\s(.+)$] where the second outlet will report successful matches and the fourth will report failures. However this expression will only match messages with extra arguments, things like "playerblobBALL" and "playerblobPLAY" will not match. I’ll keep looking into it though, let me know if this is enough.

lh


January 10, 2010 | 10:11 am

Hi Christopher,
With regexp and what bbracken suggested and what you’d like to do, I would probably do something like this with zl objects :

– Pasted Max Patch, click to expand. –

January 10, 2010 | 11:00 am

Is this what you want?

– Pasted Max Patch, click to expand. –

You can use the backreferences output for your routed output, and the not matched output to pass on for further processing if you want exact route like functionality – this is a similar approach as Luke Hall suggests (use brackets to set the backreference section of the regexp), but it should matches ANYTHING after the playerblob – with or without spaces – basically regexp can do what you need – but you need to be totally clear on exactly what cases should match and which shouldn’t – http://www.regular-expressions.info/ is a pretty useful reference for this stuff…

Alex


January 10, 2010 | 12:12 pm

Shhh. Promise not to tell anyone of the jstrigger object, it’s a secret.

– Pasted Max Patch, click to expand. –

_
johan


January 10, 2010 | 2:14 pm

I couldn’t figure out a way to do it all in one [regexp] but here’s an abstraction that mimics [route] with one argument. It will even send a "bang" if there is a match but nothing extra to route. It will currently match "playerblob hello 3" i.e. no extra symbol appended directly to "playerblob" but if you want a match like that to fail, simply change the *asterisk* in each [regexp] to a +plus+ and it should work.

lh

– Pasted Max Patch, click to expand. –

January 10, 2010 | 5:56 pm

Luke – cool patch, but is there a reason that you are matching at the end of the string?

This isn’t how route works. Currently your abstraction will match:

nomatch playerblob01 ereoiu erueriu

I don’t think it should do that for route like functionality. Also you can do the matching in one regexp – but an exact match will give you a null string "" rather than a bang. A working regexp would be:

regexp playerblob\w*\s?(.*)

Regards

Alex


January 10, 2010 | 7:02 pm

Not sure why I left the $dollar$ sign in there but you’re right. To solve the problem you mentioned simply add a ^caret^ to the beginning of each [regexp] search string. You’d need to do the same for the one you posted above too!

lh


January 10, 2010 | 7:31 pm

So I found [tap.route @searchstring playerblob @partialmatch 1] does exactly what I needed. Attached is many of the approaches everyone so kindly provided. Many of them almost work. I’m not sure I understand luke’s last suggestion. I’d like to use regexp for this as the patch needs to be easily portable and tap.tools requires a license, but at least its working. Thank you everyone for your help.

– Pasted Max Patch, click to expand. –

January 10, 2010 | 7:47 pm

Here’s the fixed version that won’t match something beginning "NOTplayerblob" etc. It’s kinda hard to figure out exactly what you want seeing as I don’t have the tap tools externals so I don’t know all possible inputs and the outputs you want in each case. Hopefully this will work for you though.

lh

– Pasted Max Patch, click to expand. –

January 10, 2010 | 10:17 pm

Yes – luke you’re totally right – proper route functionality you need to explicitly match at the start of the string – for some reason that didn’t occur to me as the problem – rather that you where explicitly matching at the end…

Thanks for that – I might need that in future…

A.


Viewing 14 posts - 1 through 14 (of 14 total)