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 Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: