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.
Write down the cases before tweaking the regex
The fastest way I know to waste time with regex is to keep changing the pattern without writing down what should match.
I usually make a tiny test set first:
AUTH-1284 yes
REGEX-42 yes
BILLING-9001 yes
AUTH- no
abc-123 no, if project keys must be uppercase
AUTH-1284-extra no, if the whole token should match
Then I adjust the expression until the matches line up with those cases.
This is more useful than staring at the regex and trying to reason it out in my head. It also catches the mistakes that do not look like mistakes at first: a missing anchor, a capture group in the wrong place, or a pattern that matches part of a longer token.
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.
You can get Regex Tester/Builder on the Mac App Store.
Related: Swift Regex Builder, nginx regex tester, and sed regex tester.