This article is for advanced users of the Slack Pattern feature. If you aren't familiar with regular expressions, try using simple Slack patterns first.
Why use a capture group?
In a regular expression, a capture group is an easy way to extract part of the matched pattern from your Slack message. You can either:
- Set a metric value to the resulting extracted value, or increase/decrease a metric value by the extracted value.
- Insert the extracted value into a newsflash message template.
To specify a named capture group, you place parentheses around the section of the regular expression that you want to capture and provide a name. Then reference the extracted value using {!name} syntax.
Example
The Product team here at Hoopla announces deployments in Slack like this: Sprint 73 has been deployed to Production at 10:05am.
We want to send kudos to them each time they deploy by creating a Pattern to trigger a newsflash:
- In the pattern section, we specify [Ss]print\s(?<release>\d+).*Production. The (?<release>\d+) portion enclosed in parentheses will match the numbers after the word sprint or Sprint and save the values under the name release.
- In the newsflash message template, we can then reference the matched numbers such as “Thank you Product Team for releasing version {!release}”.