# Getting matched OSC path from wildcard sync?

**URL:** <https://in-thread.sonic-pi.net/t/getting-matched-osc-path-from-wildcard-sync/196>\
**Category:** \[P\] Patreon Support\
**Created:** [October 8, 2017, 8:29am UTC](https://in-thread.sonic-pi.net/t/getting-matched-osc-path-from-wildcard-sync/196 "2017-10-08T08:29:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![textchimp](https://avatars.discourse-cdn.com/v4/letter/t/b77776/32.png) [@textchimp](https://in-thread.sonic-pi.net/u/textchimp)\
**Post date:** [October 8, 2017, 8:29am UTC](https://in-thread.sonic-pi.net/t/getting-matched-osc-path-from-wildcard-sync/196/1 "2017-10-08T08:29:26Z")

</div>

I’m using wildcards to match OSC message paths with `sync` (as described in Section 10.3, “Pattern Matching” of the tutorial) and wondering if anyone knows whether it’s possible to determine the path that was actually matched by a wildcard path. For example, given the following code:

`osc_vars = sync "/osc/*/multitoggle/**"`

…which could match TouchOSC messages such as “/osc/3/multitoggle/1/8/1”, or:

`osc_vars = sync "/osc/**"`

…which will match any incoming OSC message, is there any way to get the exact path that was actually matched in any instance? If not, what use are wildcards for OSC handling, since you would still need a unique `sync` for each possible path, when you want to take different actions for different paths?

Cheers!

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [October 8, 2017, 9:27am UTC](https://in-thread.sonic-pi.net/t/getting-matched-osc-path-from-wildcard-sync/196/2 "2017-10-08T09:27:04Z")

</div>

Wildcards still have use as they allow you to match against one of many inputs.

However you’re right about the benefit of knowing which osc path actually matched. Unfortunately I hadn’t figured out a super simple syntax for this by the time the deadline for getting v3 on Raspbian Stretch arrived. I therefore shipped without it with the intention of adding this functionality in a future release.

So, that said let me throw the ball back at you 🙂

What kind of syntax would you like to see which would enable you to do this?

---

<div class="post-metadata">

**Author:** ![textchimp](https://avatars.discourse-cdn.com/v4/letter/t/b77776/32.png) [@textchimp](https://in-thread.sonic-pi.net/u/textchimp)\
**Post date:** [October 8, 2017, 11:47am UTC](https://in-thread.sonic-pi.net/t/getting-matched-osc-path-from-wildcard-sync/196/3 "2017-10-08T11:47:28Z")

</div>

Thanks for the reply Sam.

I just looked at the source for `sync` and noticed that the `CueEvent` does already have a `path` attribute, so I hacked together my own solution by having `sync_event` check for an extra option `path`, which if set causes `sync` to include the matched path as the 0th element of the returned array. So I suppose that’s what I would suggest for the syntax:

`osc_vars = sync "/osc/**", path: true`

… would cause `osc_vars` to be `["/osc/2/multitoggle/1/8/1", 1.0]` or similar. This preserves the default return behaviour of `sync`.

I’ll still need to `split` the path on the slash to get each path segment. If you’re storing the matches for each wildcard within a path, that could be something else useful to return from `sync` in this situation, to avoid that `split`.

Cheers!

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [October 29, 2017, 10:05pm UTC](https://in-thread.sonic-pi.net/t/getting-matched-osc-path-from-wildcard-sync/196/4 "2017-10-29T22:05:54Z")

</div>

There is an undocumented function get\_event which can do this, although as Sam would point out don’t rely on it as it may change in future versions. I used it here [Using controllers with Sonic Pi 3](http://in-thread.sonic-pi.net/t/using-controllers-with-sonic-pi-3/306?u=robin.newman)
