tech stuff.

Debugging regex from the CLI

leave a comment »

Just stumbled across this obvious solution from the why didn’t I realize this earlier? 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

Written by Lee Verberne

2017-02-21 at 12:43

Posted in Uncategorized

Leave a comment