when using ?! in perl regex, bash interprets it as search through command history

Simple problem but I can't fix it.

I have the following perl regex:

echo ... | grep -P "(?i)(v(ersion)?)\s?(?!0)\d(\.|,)\d{1,}"

This is supposed to match every string that describes a version of something (e.g. V2,0 or version 1.2). But it doesn't match when the version starts with V0.... However, when I execute this, I get an error -bash: !0: event not found because !<string> is used to search through command history and execute the latest hit.

This basically breaks perl regex for me. How can I avoid the shell from interpreting it as a shortcut?

1

1 Answer

Use single quotes, not double quotes, to protect your regexp from the shell.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like