Issue
I need to find all instances of &var[0]
in a C++ code. Using grep -r "&.*\[0\]" .
found those but also int& aaa = bbb[0];
. How to make grep wildcard .*
to avoid whitespaces at all?
Solution
What about "&\w*\[0\]"
? \w
identifies "word characters", ie [A-Za-z_]
, so it should do what you're looking for.
EDIT: Elevating this excellent point from the comments:
\w is nonstandard, so it'd be safer to replace it with something like [[:alnum:]_]
Answered By - Jon Kiparsky Answer Checked By - Willingham (WPSolving Volunteer)