Regular Expressions: RegEx101 versus AutoHotkey

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

AHK Regex versus RegEx101: What to watch out for


1. Regex Flavor and Engine Version

FeatureAutoHotkeyregex101
EnginePCRE v8.x (PCRE1)PCRE2 by default
Unicode / Line HandlingDefaults to Windows CRLF; can override via (*ANYCRLF)Defaults to LF (\n)
Advanced SyntaxSome PCRE2 features not supportedFull 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

ConceptAutoHotkeyregex101
Where options goInside pattern start → i)abcAfter slashes → /abc/gi or inline (?i)
Common optionsi), m), s), x)Same meanings
Turn off options) closes options(?-i) syntax
Special AHK optionsO) = Object mode, P) = Position moden/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

Actionregex101AutoHotkey
Shows matchesAll at onceOne per call (loop for more)
Captured groupsVisual list of groupsm[1], m[2], or m["name"]
Return valueVisual onlyReturns 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, \2 work 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 as m["Name"].
  • Edge Cases:
    • Backrefs \8 or \9 behave 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.

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 use s) (dotall).
  • \R matches 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\E quirks 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 /g flag 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

Categoryregex101 (PCRE2)AutoHotkey (PCRE1)
EnginePCRE2PCRE v8.x
Global matching/g flagLoop manually
Option placement/pattern/gii)pattern
Default newline\n\r\n
\R rangeAll Unicode newlinesCR, LF, CRLF
Backtick handlingNoneBacktick = escape
Match outputAll at onceOne per call
Version strictnessStricterMore lenient
Named groupsSupportedSupported (v2)
Recursion limitsGenerousLimited
CalloutsShown onlySupported (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.

65 Unique Ideas for using HotStrings / Text Expansion

Back in 2022 I was on a call with Ryan Wells, a good friend of mine, and we were both discussing how underused HotStrings were.

We started throwing out different use cases.  I recorded the call and then went back and documented them.
We came up with 65 unique examples however I can guarantee you there are more!

If you’re new to AutoHotkey, we cover HotStrings in our Intro to AHK course

Do you have any that are not on this list❓

Stop Repeating Yourself! Use Text Expansion to Type Smarter

Stop Repeating Yourself! Use Text Expansion to Type Smarter


HotStrings Hacks: Grouped & Ready to Rock

Here’s your reorganized list, all dolled up in HTML. Copy-paste into a file, open in a browser, and boom—easy reading. Pro tip: Add some CSS flair if you’re feeling fancy!

Everyday Chit-Chat Boosters

These are the quick wins for casual typing—greetings, fixes, and words that trip you up.

  1. Greetings / Salutations
  2. Sign offs / signatures / P.S.
  3. Credentials
  4. Spell check
  5. Your personalized misspellings
  6. Things in other languages (thank you in Chinese, Spanish, French, etc.)
  7. Abbreviations
  8. Hard to remember words
  9. Words that are hard to spell
  10. Long words
  11. Adding trademark, copyright, capitalization, spelling etc.

Code Wizardry & Markup Magic

For devs and designers—snippets that save your sanity when coding or styling.

  1. Simple / Complex Formulas
  2. Code snippets (any programming language)
  3. Html tags
  4. BBC tagging format
  5. CSS structures
  6. Specific Hex values / RGB values
  7. Code snippets for helping you recode things (e.g., rec. = (“”=””)(“”=””)(“”=””)(“”=””))
  8. Commenting out lines
  9. Brand police (ensuring brands include ™, © etc.)

Canned Replies & Pro Tips

Ready-to-fire responses, guides, or fun zingers you tweak on the fly.

  1. Canned responses that can be personalized before sending
  2. Canned instructions how to do something
  3. Pull up favorite quotes, insults, jokes
  4. Speed up report writing (mlt. for more likely than, llt. for less likely than)

Biz & Inventory Quick-Draws

Stuff for work hustlers—lists that update easy and keep you organized.

  1. Product list of available inventory, out of stock inventory, etc.
  2. Last order / favorite product / favorite sport’s team
  3. Easily updated email distribution lists
  4. Easily updated phone / SMS texting lists
  5. Top selling products

Symbols, Supers, & Sneaky Chars

Fancy formatting and those elusive icons that make text pop.

  1. Words with Sub / super script
  2. Strange characters: Degree symbol, Trademark, copyright, creating arrow ->
  3. Characters not on your keyboard

Conversion Superpowers

Turn units, times, or cash on a dime—no calculator needed.

  1. Any type of conversion! (Distance, currency, time, volume, language, energy, etc.)
  2. Things you use together (e.g., a Phone number and name of manager usually talk to)

Contact Vault

Your rolodex on steroids—personal deets for friends, fam, or clients.

  1. Addresses
  2. Phone numbers
  3. Emails
  4. Age
  5. Birthdays
  6. Spouse / kids etc.

Pathfinding Hacks

Skip the file hunt—zap straight to your go-tos, even the nightmare network ones.

  1. Paths to frequently used files (avoid navigating / finding that file!)
  2. Paths to frequently used folders (have access to your frequently used folders in every open/save dialog box!)
  3. Paths to crazy-long / complex networked folders (if you work for a large biz, you know what I mean)

Link Launchers

Bookmarks that work everywhere—secure ’em, share ’em, map ’em.

  1. Force https on any url you type
  2. Zoom meetings
  3. Common pages you like (like a bookmark but not tied to a specific browser)
  4. Common pages you share with others
  5. HTML links to pictures/pages that have all the options you’d want
  6. Google maps

Secret Stash (Encrypt These!)

Sensitive stuff—keep it locked down, not plaintext.

  1. Crazy long & complex passwords
  2. Credit cards info
  3. API Tokens / keys
  4. Security codes
  5. Things that change on a regular basis (password, discount codes, combinations, etc.)

Handy Lists & Calendars

Repeatable rote stuff—days, months, or sales hits at your fingertips.

  1. Days of the week
  2. Months of the year

Seasonal & Short-Term Sparks

Hotstrings that come and go—like holiday cheer or flash sales.

  1. Use 1 character for a short time
  2. Use around special occasions like Christmas, Thanksgiving, Valentine’s Day, etc.
  3. During a big sale

Next-Level Ninja Moves

Fancy pants stuff—dynamic, contextual, or clipboard tricks for power users.

  1. Context sensitive (e.g., Commenting out lines (and moving to left X number of times))
  2. Dynamic string replacement (e.g., 34 m. changes to 34 m. / XXX kilometers; Sales tax, etc.)
  3. Time conversion (Insert current date; Insert date for 30 days from now; Change date to time in another time zone)
  4. Copy an image to the clipboard (and paste if you want it to)
  5. Copy content as HTML ready to paste
  6. Copy RTF (bold, color, italics, etc.) to the clipboard and paste

There ya go—your HotStrings list, HTML-style. Now go automate the world!

If you’re new to AutoHotkey, we cover HotStrings in our Intro to AHK course

Common Reasons AutoHotkey Scripts Break on Other Computers

Ever shared one of your “perfectly working” AutoHotkey scripts with a friend or co-worker, only to get a message back like:
“It doesn’t work on my computer!”
That’s because what runs smoothly on your setup can fall apart spectacularly on someone else’s.
Different Windows versions, screen sizes, permissions, and even keyboard layouts can turn your rock-solid automation into a frustrating mess.
The good news? Once you know the common pitfalls, you can build scripts that survive almost any environment.
Here’s a master checklist of the biggest troublemakers (and how to dodge them).

Why your AHK script breaks when you share it with others

Why your AHK script breaks when you share it with others


Common Reasons AutoHotkey Scripts Break on Other Computers

1) Environment & System Differences

  1. Image search dependencies – Screenshots break with different DPI, resolution, color themes, or visual styles.
  2. Coordinate-based automation – Hardcoded mouse/keystroke positions fail on different screen sizes, layouts, or scaling.
  3. Timing assumptions – Delays that work on a fast PC may be too quick on slower ones.
  4. OS version differences – Windows 10 vs 11 (and update level) can change behavior.
  5. AHK bitness/version differences – v1 vs v2 syntax, 32-bit vs 64-bit AHK, pointer size mismatches in DllCall.
  6. Different software versions – Target apps change menus, controls, or behavior across releases.
  7. Locale & encoding differences – ANSI vs UTF-8, system code pages, or decimal separators (“,” vs “.”).
  8. Missing environment variables – Assumes %APPDATA%, %ProgramFiles%, or custom vars exist when they don’t.
  9. Antivirus/security interference – AV/EDR can block SendInput, compiled EXEs, or file access.

2) File & Path Issues

  1. Hardcoded paths – Using absolute user paths instead of A_MyDocuments, A_ScriptDir, or relative paths.
  2. Relative path confusion – Working directory differs when launched via shortcut/launcher.
  3. Missing resources – Referenced images, sounds, or data files aren’t present on the target system.
  4. Drive letter assumptions – Expecting specific letters (e.g., D:, Z:) that don’t exist.
  5. Network path issues – Mapped drives vs UNC paths (Z:\ vs \\Server\Share) not interchangeable.
  6. File permission issues – Writing to protected directories without elevation.
  7. Case sensitivity – Breaks on case-sensitive environments (WSL, some network shares).

3) Error Handling & Validation

  1. No window/application validation – Acting without checking WinExist() or control presence.
  2. No application existence check – Assuming required software is installed.
  3. Missing input validation – Not validating user inputs before processing.
  4. Missing error handling – No try/catch or structured error paths; crashes on exceptions.
  5. Race conditions – Interacting before a window/control is fully loaded.
  6. Multiple instance assumptions – Not accounting for multiple windows or processes with the same name.
  7. Clipboard assumptions – Expecting text but finding an image, empty, or another format.

4) User Behavior & Assumptions

  1. Workflow assumptions – Expecting users to follow the exact same sequence of actions.
  2. Window title dependencies – Hardcoded titles change with language, app version, or file name.
  3. Keyboard layout differences – QWERTY vs AZERTY, special characters, regional keymaps.
  4. Privilege assumptions – Requires admin rights without checking/requesting.
  5. Hotkey conflicts – Assigning hotkeys already used by the system or other software.
  6. Default program assumptions – Expecting .txt to open in Notepad when user has something else.

5) Technical Implementation Issues

  1. Registry key assumptions – Keys/values exist on one system but not another.
  2. COM object availability – COM interfaces not registered on the target system.
  3. DLL dependencies – External DLLs missing or wrong architecture.
  4. Control class/ID variability – Auto-generated control IDs differ across versions/builds.
  5. UAC elevation mismatch – Non-elevated script can’t interact with elevated windows.

Pro Tips for Robust Scripts

  • Use A_ScriptDir, A_MyDocuments, and relative paths; avoid hardcoded user paths.
  • Validate windows/processes with WinExist() before acting; prefer control-based automation over coordinates.
  • Add try/catch and clear error returns; log failures.
  • Test on multiple machines/VMs with different DPI, scaling, locales, and speeds.
  • Provide setup instructions and a requirements checklist (AHK version/bitness, dependencies, permissions).