How to Write Telegram Filter Regex with ChatGPT or Claude

Phantom can filter messages with regular expressions, which is the only thing flexible enough for channels that all write in their own format. The problem is that almost nobody wants to learn regex syntax. You do not have to: your AI assistant already knows it, and this page gives it the one thing it cannot guess โ€” exactly how Phantom applies the pattern. Copy the prompt, paste a few real messages from your channel, and paste the answer into the rule.

The prompt to give ChatGPT or Claude

Copy this whole block into a new chat, replace the two placeholders at the bottom with your own messages and what you want to keep, and send it. The prompt stays in English on purpose: it is instructions for the model, and every assistant handles it best that way โ€” your messages and your answer can be in any language.

You are writing filter patterns for Phantom Forwarder, a Telegram forwarding tool. I will paste real messages from a channel; you return regular expressions.

HOW PHANTOM APPLIES THEM - follow these exactly:

1. Engine: Python `re`, matched with `re.search()`. The pattern has to match ANYWHERE inside the message, so never wrap it in `.*`.
2. No flags are passed. `.` does not match a newline and `^`/`$` anchor to the start and end of the WHOLE message, not of each line. Messages are usually multi-line, so if you need per-line anchors add the inline flag yourself: `(?m)^SELL` or `(?s)` to let `.` cross newlines.
3. CASE SENSITIVITY IS THE BIG TRAP. When the rule's "Case sensitive" switch is OFF, Phantom lowercases the message AND the pattern before matching. That silently rewrites your regex: `\S` becomes `\s`, `\D` becomes `\d`, `\W` becomes `\w`, `\B` becomes `\b` - each one flips to its opposite - and `[A-Z]` becomes `[a-z]`. So: write patterns in lowercase and avoid those uppercase escapes, OR tell me to assume "Case sensitive" is ON and I will keep the case as written. Say which one you want.
4. An invalid regex does not raise an error: Phantom falls back to a plain substring search of the pattern text. A broken pattern therefore looks like it "half works". Give me patterns you are sure compile.

WHERE THEY ARE USED:
- Filters -> keywords to allow / keywords to block, with "Use regex" ON. Allow list: the message passes if AT LEAST ONE pattern matches. Block list: the message is dropped if ANY pattern matches.
- Find & Replace, with "Use regex" ON. There the replacement string supports backreferences: `\1`, `\2`, and named groups.

WHAT I NEED FROM YOU:
- one pattern per line, nothing else on the line
- under each, one short sentence saying what it matches and what it does not
- prefer several simple patterns over one clever one: they are easier to switch off individually
- tell me explicitly if a pattern needs "Case sensitive" ON

HERE ARE MY MESSAGES (paste 3-5 real ones, including at least one you do NOT want forwarded):

<<< paste here >>>

WHAT I WANT: <<< describe it, e.g. "only messages that open a new trade, not the updates" >>>

Three behaviours that make a regex look right and behave wrong

These are the reasons a pattern that works in an online regex tester can still misbehave in a rule. They are already inside the prompt above, but it is worth knowing them yourself.

  • The pattern is searched anywhere inside the message, not matched against the whole of it. You never need to wrap it in .* โ€” doing so only makes it slower.
  • When "Case sensitive" is OFF, Phantom lowercases the pattern together with the message. That flips \S into \s, \D into \d, \W into \w and \B into \b โ€” each becomes its own opposite โ€” and turns [A-Z] into [a-z]. If your pattern relies on any of those, switch "Case sensitive" ON.
  • An invalid pattern does not produce an error. Phantom falls back to searching for the pattern as plain text, so a broken regex looks like it half works. If a filter behaves oddly, that is the first thing to suspect.

Where to paste the result

Regular expressions in filters and in Find & Replace are available from the Gold plan upwards. Plain keyword filters, without regex, work on every paid plan.

  1. Open the rule, tab Filters, and switch "Use regex" on.
  2. Put the patterns that should let a message through into the allow list: one per line. A message passes if at least one of them matches.
  3. Put the patterns that should drop a message into the block list. A message is dropped if any of them matches, even when an allow pattern also matched.
  4. For rewriting rather than filtering, use the Transform tab, Find & Replace, with "Use regex" on: there the replacement supports backreferences like \1.
  5. Send a test message in the source chat and check the destination before leaving the rule running.

What to ask for, in practice

The more real messages you paste, the better the answer. Always include at least one message you do NOT want forwarded: without a counter-example the assistant has nothing to separate.

  • Only messages that open something new, not the follow-ups: give the assistant one example of each and let it find what separates them.
  • Everything except the channel's own advertising: paste two promotional messages and ask for block patterns.
  • Only one instrument or one keyword, with its common misspellings and spacing variants.
  • Messages above or below a certain structure โ€” a number of lines, the presence of a price, a specific emoji.

Common questions

Do I need to know regular expressions to use this?

No. That is the point of the page: the assistant writes them, you paste them into the rule. It helps to read the three behaviours above so you can tell when something is off.

Why does my pattern work in an online tester but not in the rule?

Almost always the case sensitivity switch. With "Case sensitive" off, Phantom lowercases your pattern as well as the message, which flips escapes like \S, \D, \W and \B into their opposites. Turn "Case sensitive" on, or ask the assistant for an all-lowercase pattern.

What happens if I paste a pattern with a syntax error?

Nothing visible: Phantom does not reject it. It searches for your pattern as if it were plain text, so the filter appears to work in some cases and not in others. If a filter behaves inconsistently, check the pattern compiles.

Can I use the same approach for Find & Replace?

Yes, and the prompt covers it. In Find & Replace the replacement string also supports backreferences, so the assistant can write patterns that keep part of the original text and rewrite the rest.

Which plans include regex?

Gold and above, both in Filters and in Find & Replace. Simple keyword filters without regex are available on the lower paid plans.

Try Phantom Forwarder free

7-day trial, unlimited rules. Cloud-based, anonymous, nothing to install.

Related

More guides