route partialmatch? / feature request

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

    • Jan 10 2010 | 1:40 am
      the almighty regexp, at your service:
    • Jan 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".
    • Jan 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.
    • Jan 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.
    • Jan 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 :
    • Jan 10 2010 | 11:00 am
      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 - is a pretty useful reference for this stuff...
    • Jan 10 2010 | 12:12 pm
      Shhh. Promise not to tell anyone of the jstrigger object, it's a secret.
      _ johan
    • Jan 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.
    • Jan 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?(.*)
    • Jan 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!
    • Jan 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 requires a license, but at least its working. Thank you everyone for your help.
    • Jan 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.
    • Jan 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...