Regex Tester for macOS
I usually test regular expressions before I paste them into code. That sounds obvious, but it still saves me from small mistakes — wrong escaping, missing capture groups, and patterns that work in one place but not another.
My preference on the Mac is simple: test the pattern against real sample text, then copy it into the tool that needs it.
Why use a Mac regex tester
A regular expression is rarely just the pattern. It usually comes with a few details attached:
- sample input
- match options such as case-insensitive or multiline matching
- capture groups
- the replacement string, if I am doing a search-and-replace
- the engine or tool that will run it
That last one matters. A regex that works in JavaScript may need changes before it works in grep, sed, Swift, nginx, or Ruby.
Regex for macOS is useful when I want a focused place to edit the pattern and sample text side by side. I can see the matches, inspect capture groups, and copy the final pattern into code or Terminal.
A small example
Say I want to pull ticket IDs out of text like this:
Fixed AUTH-1284 and REGEX-42.
QA needs to check BILLING-9001.
I would start with:
\b[A-Z]+-\d+\b
That matches:
AUTH-1284
REGEX-42
BILLING-9001
Then I decide whether I need a capture group:
\b([A-Z]+)-(\d+)\b
Now I can inspect the project key and number separately:
- Group 1:
AUTH,REGEX,BILLING - Group 2:
1284,42,9001
That is the point of using a tester. I do not want to guess whether group 1 is what I think it is.
Taking it to Terminal
On macOS, I usually start with grep -E when I need extended regular expressions:
grep -E '\b[A-Z]+-[0-9]+\b' tickets.txt
For replacement work, I usually reach for sed -E:
sed -E 's/([A-Z]+)-([0-9]+)/\1 ticket \2/g' tickets.txt
The pattern is close to the one I tested. Shell quoting and the regex engine both matter, so I still check the command before using it on real files. For example, macOS sed does not treat \b as the same word-boundary token that many programming-language regex engines do.
What I check before using a regex
The short checklist:
- Does it match the examples I expect?
- Does it avoid examples I do not want?
- Are the capture groups in the right order?
- Does it still work when the input has multiple lines?
- Do I need a case-insensitive option instead of writing
[A-Za-z]everywhere? - Does the destination tool support the features I used?
Lookahead, lookbehind, and backreferences are useful, but they are also where portability starts to get worse. I use them when the target supports them and keep the pattern simpler when it does not.
When I use Regex for macOS
I use Regex for macOS when I want a native app instead of another browser tab. It does one job: edit and test regular expressions on the Mac.
I mostly want a focused place to work through the pattern, confirm the matches, and copy it into the next thing.
Related: Swift Regex Builder, nginx regex tester, and sed regex tester.