Skip to content

Can you use a regular expression as a keyword trigger?

IQ
Imran Q.

Customers paste an order reference like AB-4821 and I want the flow to recognise it and look it up. A keyword list obviously will not work for that. Is there a pattern option?

4 Answers

Best answer

HS

Yes. Pattern mode takes a PCRE regular expression, which is the right tool when you are matching a shape rather than a word: an order number, a postcode, a date, a promo code.

A concrete example. An order lookup flow where customers paste a reference like AB-4821 uses the pattern ^[A-Z]{2}-\d{4}$. Contains mode cannot express that, and equals mode would need every possible reference listed.

Three things to know before you rely on it.

Invalid patterns fail closed. A pattern with a syntax error does not match anything, rather than matching everything. Your automation goes quiet instead of replying to every message, which is the safer of the two failure modes but still worth testing.

There is a backtracking budget. A pattern that takes too long is abandoned rather than allowed to run away. Catastrophic backtracking cannot hang your automation, but an over-clever pattern may stop matching under load. Keep patterns simple and anchored.

Pattern mode sits below exactly matches in priority. If a message satisfies both a pattern automation and an equals automation, the equals one answers.

Test the pattern against real messages before publishing, including the messy ones with a greeting in front of the reference. If your customers write "hi here is my order AB-4821", an anchored ^...$ pattern will not match it.

DK

The fail closed behaviour is the right choice. Silent is better than replying to everything.

JP

Anchoring caught us out, our customers always say hello first. ---

CT

Confirmed. The fail closed behaviour is deliberate for exactly this reason.

Sign in to reply and save your draft.

Can you use a regular expression as a keyword trigger?: Community | ChatinFlow