How Do You Use Regular Expressions to Filter Telegram Messages?
Most filtering needs a word list and nothing more. Occasionally it needs a shape: a code with a fixed format, a number in a range, a line that has to begin in a particular way. That is what pattern matching is for, and it is available from the Gold plan upwards. It is also easy to get subtly wrong, so this page spends more time on the traps than on the syntax.
How a pattern is matched here
A pattern matches if it is found anywhere in the message: it is not anchored to the beginning. Writing `entry` finds it in the middle of a sentence, and if you need it at the start of a line you say so explicitly in the pattern.
Patterns are used in both lists. In the allowed list, one pattern matching is enough to relay the message; in the blocked list, one pattern matching is enough to drop it.
Trap one: a broken pattern does not fail loudly
If the expression cannot be interpreted — an unbalanced bracket, a stray quantifier — nothing is skipped and no error appears. The filter falls back to looking for that text literally, exactly as if pattern mode were off.
That behaviour is deliberate, because the alternative is a rule that stops relaying because of a typo. But it means a broken pattern can look like it is working, quietly matching almost nothing. Test with a message you know should pass before leaving it running.
Trap two: capitalisation changes your pattern, not just the text
By default the comparison ignores capitalisation, and it does that by lowering the case of both the text and the pattern. For ordinary words that is exactly right. For a pattern it can invert your meaning: an uppercase escape such as one meaning "not a digit" becomes its lowercase counterpart, which means "a digit", and a range written in capitals becomes the same range in lower case.
The rule to remember is short: if your pattern contains uppercase letters that carry meaning, switch strict capitalisation on. If it is all lower case, leave it off and enjoy the case-insensitive matching.
Patterns worth having
Anything more elaborate than these is usually a sign that the source is inconsistent, and a second, simpler rule will age better than one clever pattern.
- A word on its own rather than inside another word, so that "buy" does not match "buyback".
- A ticker in capitals immediately followed by a number, with strict capitalisation switched on.
- A line that begins with a given symbol, to catch a fixed post format.
- A number range, which a keyword list cannot express at all.
If you do not want to write patterns
You do not have to. There is a separate guide on describing the filter in plain language and having an assistant produce the pattern for you, which is the faster route for most people. And for content that is easier to judge than to describe, the AI content filter takes a criterion written in ordinary words instead of a pattern.
Which plans include it
Pattern matching in filters starts on the Gold plan; the keyword lists themselves are available from Smart. The plan comparison is on the pricing page.
Common questions
Can I use a regular expression to filter forwarded Telegram messages?
Yes, from the Gold plan upwards. Switch pattern mode on for the rule and the keywords become patterns, matched anywhere in the message rather than only as plain text.
What happens if my pattern has a syntax error?
Nothing breaks and nothing is skipped: the filter falls back to searching for that text literally. It is safe, but it means a broken pattern can look like it is working while matching almost nothing, so test it before relying on it.
Why does my pattern with uppercase escapes behave the opposite way?
Because with case-insensitive matching both the text and the pattern are lowered in case, which turns an uppercase escape into its lowercase counterpart and inverts its meaning. Switch strict capitalisation on whenever your pattern uses uppercase that carries meaning.
Is the pattern anchored to the start of the message?
No, it matches anywhere. Anchor it in the pattern itself if you need it at the beginning of a line.
Try Phantom Forwarder free
7-day trial, unlimited rules. Cloud-based, anonymous, nothing to install.
Related
More guides
- How to Write Telegram Filter Regex with ChatGPT or Claude
- 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 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?