How To Use Wildcards In The Path

<< Back to the .Networking page

You can use wildcard characters when using Shared Dictionary paths:

The * wildcard matches zero or more characters traversing sub-trees.
For example, /countries/*/capital would match /countries/Canada/capital and /countries/USA/capital.

The ? wildcard is similar, but scans only one level in the hierarchy.
For example, /countries/?/population would match /countries/Canada/population but not /countries/USA/California/population.

The + wildcard matches a sub-tree and its root.
For example, /countries/Canada+ matches /countries/Canada and any keys under it, like /countries/Canada/anthem, /countries/Canada/Alberta/capital.

The & wildcard matches a GUID (Globally Unique Identifier) string.
For example, /countries/& matches /countries/{1a743fe3-5a5f-ed43-c32b-345ea8fb3c5a}.

The ^ wildcard matches a string of consecutive numbers.
For example, /countries/Canada^ matches /countries/Canada1 and /countries/Canada123, but not /countries/Canadas.

Exercise 1

Cover the righthand column and see if you can guess which keys match which subscription patterns.

No Wildcard

SubscriptionKeyMatch
/note/note2No
/note/note2/textNo
/note/noteYes
/note/note/textNo

* Wildcard

SubscriptionKeyMatch
/*/noteYes
/*/note/textYes
/*/note2Yes
/note/*/note/textYes
/note/*/note/text/fontYes
/note/*/note2No
/note/*/font/note/text/fontYes
/note/*/font/note/caption/text/fontYes
/note/*/font/note/fontNo
/note/*font/note/text/fontYes
/note/*font/note/caption/text/fontYes
/note/*font/note/fontYes
/note/*font/note/titlefontYes
/note*font/note/fontYes
/note*font/notefontYes
/note*/noteYes
/note*/note2Yes
/note*/note2/textYes

? Wildcard

SubscriptionKeyMatch
/?/noteYes
/?/note/textNo
/note/?/note/textYes
/note/?/noteNo
/note?/text/note2/textYes
/note?/text/note2/caption/textNo
/note?/text/note/textNo

+ Wildcard

SubscriptionKeyMatch
/+/noteYes
/+/note/textYes
/+/note2Yes
/note+/noteYes
/note+/note2No
/note+/note2/textYes
/note+/text/note2/textERROR!

& Wildcard

SubscriptionKeyMatch
/note/&/text/note/caption/textNo
/note/&/text/note/{1a743fe3-5a5f-ed43-c32b-345ea8fb3c5a}/textYes
/note&/text/note{1a743fe3-5a5f-ed43-c32b-345ea8fb3c5a}/textYes

^ Wildcard

SubscriptionKeyMatch
/note^/note1Yes
/note^/note11Yes
/note^/notesNo
/note^/text/note1/textYes