viewof pattern = Inputs.text({
label: "Topic pattern:",
value: "sensor.temperature.*",
width: 400,
placeholder: "e.g., sensor.*.room1 or sensor.#"
})
viewof routingKey = Inputs.text({
label: "Routing key to test:",
value: "sensor.temperature.room1",
width: 400,
placeholder: "e.g., sensor.temperature.room1.zone2"
})
{
function matchesPattern(key, pat) {
if (pat.includes('#')) {
const parts = pat.split('#');
if (parts.length !== 2) return false;
const [prefix, suffix] = parts;
const cleanPrefix = prefix.endsWith('.') ? prefix.slice(0, -1) : prefix;
const cleanSuffix = suffix.startsWith('.') ? suffix.slice(1) : suffix;
if (cleanPrefix && !key.startsWith(cleanPrefix)) return false;
if (cleanSuffix && !key.endsWith(cleanSuffix)) return false;
return true;
}
if (pat.includes('*')) {
const keyParts = key.split('.');
const patParts = pat.split('.');
if (keyParts.length !== patParts.length) return false;
for (let i = 0; i < patParts.length; i++) {
if (patParts[i] !== '*' && patParts[i] !== keyParts[i]) {
return false;
}
}
return true;
}
return key === pat;
}
const matches = matchesPattern(routingKey, pattern);
const keyParts = routingKey.split('.');
const patParts = pattern.split('.');
return html`<div style="margin: 20px 0; padding: 20px; background: #f8f9fa; border-left: 4px solid #2C3E50; border-radius: 4px;">
<h4 style="margin-top: 0; color: #2C3E50;">Pattern Match Result</h4>
<div style="background: white; padding: 20px; border-radius: 8px; border: 3px solid ${matches ? '#16A085' : '#E74C3C'}; margin: 15px 0;">
<div style="text-align: center;">
<div style="font-size: 48px; margin: 10px 0;">
${matches ? 'MATCH' : 'NO MATCH'}
</div>
<div style="font-size: 24px; font-weight: bold; color: ${matches ? '#16A085' : '#E74C3C'}; margin: 10px 0;">
${matches ? 'MATCH' : 'NO MATCH'}
</div>
<div style="font-size: 14px; color: #7F8C8D;">
Pattern: <code style="background: #f0f0f0; padding: 2px 6px; border-radius: 3px;">${pattern}</code><br/>
Routing Key: <code style="background: #f0f0f0; padding: 2px 6px; border-radius: 3px;">${routingKey}</code>
</div>
</div>
</div>
<div style="background: white; padding: 15px; border-radius: 8px; margin-top: 15px;">
<div style="font-size: 14px; color: #7F8C8D; margin-bottom: 10px;">Word count analysis:</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px;">
<div>
<strong style="color: #2C3E50;">Pattern segments:</strong> ${patParts.length}<br/>
<code style="background: #f0f0f0; padding: 2px 6px; border-radius: 3px; font-size: 12px;">
${patParts.join(' . ')}
</code>
</div>
<div>
<strong style="color: #2C3E50;">Routing key segments:</strong> ${keyParts.length}<br/>
<code style="background: #f0f0f0; padding: 2px 6px; border-radius: 3px; font-size: 12px;">
${keyParts.join(' . ')}
</code>
</div>
</div>
</div>
<div style="margin-top: 15px; padding: 12px; background: #e8f4f8; border-radius: 6px; border-left: 3px solid #3498DB;">
<strong style="color: #3498DB;">Remember:</strong>
<span style="color: #2C3E50;">
<code>*</code> matches exactly ONE word, <code>#</code> matches ZERO or more words.
${!matches && pattern.includes('*') && keyParts.length !== patParts.length ?
' Try using # instead of * for variable-depth hierarchies.' : ''}
</span>
</div>
</div>`;
}Interactive Calculator: Topic Wildcard Pattern Matcher
Interactive Calculator: Topic Wildcard Pattern Matcher
animation
amqp
protocols
messaging
Try Change routing key to test to sensor.temperature.room1.zone2.
Observe Watch Pattern Match Result and Routing key segments for sensor.temperature.room1.zone2.
Explain Explain why sensor.temperature.* does not match sensor.temperature.room1.zone2.
Technical boundaries. Patterns containing # use prefix and suffix matching; more than one # returns NO MATCH. Patterns containing * without # require equal segment counts.