Differences Between AHK RegEx and RegEx101
We like to use RegEx101 for testing our Regular Expressions in AutoHotkey.
It’s a great tool however there are some differences between AutoHotkey and Reg101. We’ve outlined the “bigies” below.
If you’re new to Regular Expressions, you might want to check out our Intro to RegEx Course
Overview
AutoHotkey (AHK) uses the PCRE (Perl-Compatible Regular Expressions) engine — specifically an older PCRE1 (v8.x) — while regex101 defaults to PCRE2 (used in modern PHP).
They’re closely related, but differ in defaults, features, and option handling, which can cause subtle mismatches.
If you select “PCRE (PHP < 7.3)” on regex101, that’s the closest match to AutoHotkey’s engine.
AutoHotkey RegEx Rules
You can learn “excaly” how RegEx in AutoHotkey works by studying this page
AHK Regex versus RegEx101: What to watch out for

1. Regex Flavor and Engine Version
| Feature | AutoHotkey | regex101 |
|---|---|---|
| Engine | PCRE v8.x (PCRE1) | PCRE2 by default |
| Unicode / Line Handling | Defaults to Windows CRLF; can override via (*ANYCRLF) | Defaults to LF (\n) |
| Advanced Syntax | Some PCRE2 features not supported | Full PCRE2 feature set |
Notable Differences:
AHK’s PCRE1 is more lenient about odd syntax (like empty group names or stray hyphens), while regex101’s PCRE2 enforces stricter validation and modern Unicode handling.
⚙️ 2. Option / Modifier Syntax
| Concept | AutoHotkey | regex101 |
|---|---|---|
| Where options go | Inside pattern start → i)abc | After slashes → /abc/gi or inline (?i) |
| Common options | i), m), s), x) | Same meanings |
| Turn off options | ) closes options | (?-i) syntax |
| Special AHK options | O) = Object mode, P) = Position mode | n/a |
AHK also supports extra newline control tokens like (*ANYCRLF) and (*BSR_ANYCRLF).
3. Global Matching
- regex101 / PCRE: “Global” (
/g) means find all matches automatically. - AutoHotkey:
RegExMatch()returns only the first match.- To get all matches, loop manually and update the start position.
RegExReplace()replaces all matches by default.
pos := 1
while pos := RegExMatch(haystack, "pattern", m, pos + (pos ? StrLen(m[0]) : 0))
MsgBox m[0]
4. Output & Return Differences
| Action | regex101 | AutoHotkey |
|---|---|---|
| Shows matches | All at once | One per call (loop for more) |
| Captured groups | Visual list of groups | m[1], m[2], or m["name"] |
| Return value | Visual only | Returns position (1-based) or 0 if no match |
In AHK v2, RegExMatch() returns a match object with properties like .Pos, .Len, and .Name.
5. Capturing Groups & Backreferences
- Backreferences
\1,\2work normally inside the regex pattern itself (for example,(\w+)\s+\1). - When using
RegExReplace()in AutoHotkey, replacement backreferences use dollar syntax — e.g.$1,$2— not backslashes. - Named groups like
(?P<Name>...)or(?<Name>...)are supported in AHK v2 and can be accessed asm["Name"]. - Edge Cases:
- Backrefs
\8or\9behave differently — PCRE1 (AHK) may treat them as errors or literals depending on context, while PCRE2 (regex101) is stricter. - Empty or duplicate group names are tolerated in AHK (PCRE1) but rejected in regex101’s PCRE2 flavor.
- Backrefs
Summary:
Use \1, \2 for backreferences inside the pattern,
and $1, $2 for captured groups used in RegExReplace() replacement strings.
6. Escaping and String Handling in AHK
- AHK uses backtick (`) as an escape in string literals.
- Regex strings often need extra escaping — e.g.
"\\d+"or'\\d+'. \r,\n, and\\must be handled carefully.- Literal backticks in regex must be escaped as
``.
This is a major reason regexes from regex101 may fail when copied directly into AHK scripts.
7. Line Break and \R Behavior
- In AHK,
.doesn’t match newlines unless you uses)(dotall). \Rmatches only CR, LF, or CRLF by default.- Use
(*ANYCRLF)or(*ANY)to include full Unicode line breaks. - regex101 defaults to broader newline support (
\n-based).
8. Performance, Limits, and Internal Behavior
- AHK caches the 100 most recent compiled regexes.
- Deep recursion or heavy backtracking can trigger runtime errors like “recursion too deep.”
- regex101’s sandbox has fewer execution limits.
- AHK’s memory and PCRE limits are compiled in — not configurable at runtime.
9. Miscellaneous Engine Differences
- No variable-length lookbehind in AHK (PCRE1).
- Some POSIX class syntax (like
[[:punct:]b]) behaves differently. - Quantifier and
\Q\Equirks differ slightly. \p{}Unicode classes work inconsistently unless Unicode mode is enabled (default in v2).
⚡ 10. Practical Tips When Moving Between regex101 and AHK
✅ On regex101:
- Select “PCRE (PHP < 7.3)”.
- Avoid PCRE2-only features.
- Remember: no
/gflag in AHK — use loops instead.
✅ In AHK Code:
- Prefix options (e.g.,
i)pattern). - Escape backslashes/backticks properly.
- Loop
RegExMatch()for multiple results. RegExReplace()is global by default.- Be explicit about newline handling.
Summary Table
| Category | regex101 (PCRE2) | AutoHotkey (PCRE1) |
|---|---|---|
| Engine | PCRE2 | PCRE v8.x |
| Global matching | /g flag | Loop manually |
| Option placement | /pattern/gi | i)pattern |
| Default newline | \n | \r\n |
\R range | All Unicode newlines | CR, LF, CRLF |
| Backtick handling | None | Backtick = escape |
| Match output | All at once | One per call |
| Version strictness | Stricter | More lenient |
| Named groups | Supported | Supported (v2) |
| Recursion limits | Generous | Limited |
| Callouts | Shown only | Supported (callback) |
In Short
Regex in AutoHotkey is mostly PCRE-compatible but wrapped with AHK-specific syntax and runtime quirks.
- No global flag → you must loop
- Option prefixes differ
- AHK escape rules can trip you up
- Line endings and Unicode differ slightly
- Backreferences inside patterns use
\1; replacement backrefs use$1.
Otherwise, 95% of regex patterns behave identically between regex101 and AHK.

