Debugging regex from the CLI

Posted on Feb 21, 2017

Just stumbled across this obvious solution from the why didn’t I realize this earlie r? department. GNU grep makes an great regex debugger!

The secret is combining -P (for perlre) with --color to color the matched pattern. For example:

% echo -e '123\n123.123' | grep -P '^\d+(?!\.\d)'
123
123.123
% echo -e '123\n123.123' | grep -P '^\d+(?![\.\d])'
123