Skip to main content

Regular Expressions

This example demonstrates how to use regular expressions in the configuration.

It does to following with the message subject:

  • Ignores a common subject prefix
  • Captures the school name using the capture group (?<school>...)
  • Captures the report type using the capture group (?<reportType>...)
  • Captures the report sub type using the capture group (?<reportSubType>...)
  • Capture the date as the final part of the subject using the capture group (?<date>...)

The extracted data is finally used to dynamically define the location of the attachment to be stored using: .../Reports/${message.subject.match.school}/All Reports/${message.subject.match.reportType}/${message.subject.match.reportSubType}/${message.subject.match.date}-${attachment.name}

👉 Edit this example in the playground.

{
"description": "Regular expressions allow to define patterns and extract values to simplify the configuration.",
"settings": {
"markProcessedMethod": "mark-read"
},
"global": {
"thread": {
"match": {
"query": "has:attachment -in:trash -in:drafts -in:spam after:${date.now:date::yyyy-MM-dd} is:unread subject:\"[GmailProcessor-Test] regularExpressions\""
}
}
},
"threads": [
{
"match": {
"query": "from:${user.email}"
},
"messages": [
{
"name": "extract-message-fields-from-subject",
"match": {
"subject": "regularExpressions (?<school>[^-]+)-(?<reportType>[^-]+)-(?<reportSubType>[^-]+)-(?<date>[0-9-]+)"
},
"attachments": [
{
"match": {
"name": "^sample\\.docx$"
},
"actions": [
{
"name": "attachment.store",
"args": {
"location": "/GmailProcessor-Tests/e2e/regularExpressions/Reports/${message.subject.match.school}/All Reports/${message.subject.match.reportType}/${message.subject.match.reportSubType}/${message.subject.match.date}-${attachment.name}",
"conflictStrategy": "update"
}
}
]
}
]
}
]
}
]
}

Source: regularExpressions.ts