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.
- Open the rule, tab Filters, and switch "Use regex" on.
- 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.
- 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.
- For rewriting rather than filtering, use the Transform tab, Find & Replace, with "Use regex" on: there the replacement supports backreferences like \1.
- 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
- How to Forward from a Telegram Channel with Forwarding Restrictions
- How to Forward Telegram Messages Without Showing Your Account
- Cloud Service to Auto-Forward a Telegram Channel to Another 24/7
- Best Tools to Automatically Forward Telegram Messages Between Channels
- Telegram Forwarding Scripts, GitHub Projects and Modded Apps: What Actually Works
- Why Are My Telegram Messages Not Being Forwarded?
- Why Does Telegram Limit an Account, and How Do You Avoid It?
- Why Do Telegram Accounts Get Banned, and Can You Get One Back?
- How Do You Find a Telegram Channel, Group or User ID?
- What Is Telegram Two-Step Verification, and Should You Turn It On?
- Is There a Free Way to Forward Telegram Messages Automatically?
- How Do You Mass-Forward or Import Past Telegram Messages?
- How Do You Forward Messages From a Telegram Forum Topic?
- Does Telegram Forwarding Keep Running When My Computer Is Off?
- How Do You Forward Only the Telegram Messages That Contain Certain Words?
- How Do You Forward Only Photos, Videos or Files From a Telegram Chat?
- How Do You Replace Words or Links While Forwarding Telegram Messages?
- How Do You Forward Only the Messages From Certain People in a Telegram Group?
- How Do You Stop Forwarding One-Word Telegram Messages?
- How Do You Use Regular Expressions to Filter Telegram Messages?
- How Do You Add Your Own Line Above or Below a Forwarded Telegram Message?
- How Do You Change or Remove the Formatting of Forwarded Telegram Messages?
- How Do You Remove or Replace Links in Forwarded Telegram Messages?
- How Do You Delay a Forwarded Telegram Message?
- How Do You Stop the Same Message Arriving Twice?
- How Do You Forward One Telegram Channel to Several Destinations at Once?
- When Someone Edits the Original, Does the Forwarded Copy Change Too?
- If the Original Message Is Deleted, Can the Forwarded Copy Be Deleted Too?
- What Is Ghost Mode, and What Does It Actually Change?
- How Do You Automatically Translate Forwarded Telegram Messages?
- How Do You Shorten Long Telegram Messages While Forwarding Them?
- How Do You Filter Telegram Messages by Describing What You Want in Plain Language?
- How Do You Filter Telegram Messages That Are Published as Screenshots?
- How Do You Rewrite Forwarded Telegram Messages in Your Own Style?
- What Exactly Arrives in the Destination: Buttons, Pinned Posts, Albums and Copies That Expire
- How Do You Remove Mentions, Hashtags or Emoji From Forwarded Telegram Messages?
- How Do You Forward Telegram Messages Only During Certain Hours or Days?
- Should a Forwarded Telegram Message Show Where It Came From?
- How Do You Relay Trading Signals From a Telegram Channel Into Your Own?
- How Do You Combine Several Telegram Channels Into One Feed Without Duplicates?
- How Do You Repost Deals From a Telegram Channel With Your Own Links?
- How Do You Follow a Telegram Channel Written in a Language You Do Not Read?
- How Do You Keep a Telegram Group Organised by Forwarding Into Topics?
- How Do You Forward Only the Photos From a Telegram Channel?
- How Do You Keep a Forwarding Destination From Piling Up?
- How Do You Move From a Home-Made Telegram Forwarding Script to a Cloud Service?