route partialmatch? / feature request

Christopher Overstreet's icon

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...

Ben Bracken's icon
Max Patch
Copy patch and select New From Clipboard in Max.

the almighty regexp, at your service:

Christopher Overstreet's icon

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".

Christopher Overstreet's icon

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.

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

Thanks for the help.

Luke Hall's icon

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

BenCello's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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 :

AlexHarker's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Is this what you want?

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

jvkr's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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

_
johan

Luke Hall's icon

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.

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

lh

AlexHarker's icon

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

Luke Hall's icon

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

Christopher Overstreet's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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.

Luke Hall's icon

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.

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

lh

AlexHarker's icon

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.