> ## Documentation Index
> Fetch the complete documentation index at: https://hashbot.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Regex

> Regex filters (short for *regular expressions*) allow for advanced pattern matching when detecting scam usernames or impersonators. They’re more granular and powerful than phrase filters — but they require a bit more care and testing.

### What is Regex?

Regex lets you define **search patterns** that match a wide range of text combinations. This is especially helpful when scammers use unpredictable variations of names or keywords.

<Check>
  Want to test your regex? Visit [regex101.com](https://regex101.com/) (select the **Java** flavor) for testing and its reference guide — it uses the same matching engine as Hashbot.
</Check>

### Basic Example

`/name-filters add regex ^Pascal$`

This matches **only** the exact word `Pascal`.

* `^` = start of the name
* `Pascal` = exact characters
* `$` = end of the name

So it will **only** match: `Pascal`\
It will **not** match: `Pascal_`, `SirPascal`, or `pascal`

### Case-Insensitive Example

To make a regex case-insensitive, use `(?i)` at the beginning:

`/name-filters add regex (?i)^Pascal$`

This will match:

* `pascal`
* `Pascal`
* `PASCAL`
* `pAsCaL`

But **won’t** match:

* `Pascall`
* `this is pascal`
* `0xPascal`

### Recommended Filter Example

`/name-filters add regex (?i) bot$`

This filter targets any username ending in a space followed by "bot" — a common impersonation tactic.

It will match:

* `OpenSea BOT`
* `AB bot`
* `Doodles Best Bot`

It will **not** match:

* `bottom`
* `best bots`
* `bot` (without a space in front)

<Info>
  **Note**: There is an intentional space in the filter: `(?i) bot$`
</Info>

### Quick Reference

| Syntax   | Meaning                      | Example                                         |
| -------- | ---------------------------- | ----------------------------------------------- |
| `.`      | Any single character         | `sc.m` matches `scam`, `sc@m`, `sc1m`           |
| `*`      | Zero or more of the previous | `bo*t` matches `bt`, `bot`, `boot`              |
| `+`      | One or more of the previous  | `bo+t` matches `bot`, `boot` but not `bt`       |
| `?`      | Zero or one of the previous  | `colou?r` matches `color` and `colour`          |
| `[abc]`  | Any character in the set     | `[a@4]dmin` matches `admin`, `@dmin`, `4dmin`   |
| `[^abc]` | Any character NOT in the set | `[^a-z]bot` matches `1bot` but not `abot`       |
| `^`      | Start of the name            | `^admin` matches `admin_123` but not `notadmin` |
| `$`      | End of the name              | `bot$` matches `scambot` but not `bottled`      |
| `(a\|b)` | Either a or b                | `(support\|help)` matches both                  |
| `(?i)`   | Case-insensitive mode        | `(?i)admin` matches `ADMIN`, `Admin`, etc.      |
| `\`      | Escape a special character   | `\.com` matches literal `.com` (not "Xcom")     |

<Warning>
  **Escape special characters.** Characters like `.` `*` `+` `?` `(` `)` `[` `]` `{` `}` `\` `|` `^` `$` have special meaning in regex. To match them literally, prefix with `\`. For example, use `\.` to match a period and `\(` to match a parenthesis.
</Warning>

### Common Filter Patterns

| Goal                        | Pattern          | Matches                      |
| --------------------------- | ---------------- | ---------------------------- |
| Names ending in "bot"       | `(?i) bot$`      | `OpenSea BOT`, `AB bot`      |
| Names starting with "admin" | `(?i)^admin`     | `Admin_NFT`, `administrator` |
| Catch "@" substitution      | `(?i)[a@]dmin`   | `admin`, `@dmin`             |
| Block leet speak            | `(?i)supp[o0]rt` | `support`, `supp0rt`         |
| Exact name only             | `^Pascal$`       | `Pascal` (nothing else)      |

### Limitations

Hashbot uses **Java's regex engine**. Most standard regex features are supported, including:

* **Inline flags** like `(?i)` for case-insensitive mode
* **Lookahead/lookbehind** — `(?=...)`, `(?!...)`, `(?<=...)`, `(?<!...)`
* **Character classes**, **quantifiers**, **alternation**, and **anchors**

<Note>
  **Possessive quantifiers** (`*+`, `++`) and **atomic groups** (`(?>...)`) are not supported.
</Note>

### Caution & Best Practices

* Always **test your regex** on [regex101.com](https://regex101.com/) before adding it (select the **Java** flavor for best accuracy)
* Run `/cleanse` after adding a new filter — results are displayed with a **"Review on Dashboard"** button at [dashboard.hashbot.com](https://dashboard.hashbot.com)
* Avoid overly broad patterns like `.+` or `.*` — they match nearly everything
* If you accidentally create an overly broad filter:
  1. Use `/settings pause pause-state:pause` to stop Hashbot from acting
  2. Remove the problematic filter
  3. Use `/settings pause pause-state:unpause` to resume normal operation
  4. Cancel any pending `/cleanse` jobs if needed

### Need Help?

Regex can be tricky. If you’re not confident, join our [Support Discord](https://discord.gg/hashbot) and open a ticket.\
We’re happy to help build or review filters with you.
