I answered this question on SuperUser that was something related to kind of Regular expressions used while grepping an output.
The answer I gave was this :
tail -f log | grep "some_string.*some_string"
And then, In three comments to my answer @Bob wrote this :
.*
is greedy and might capture more than you want..*?
is usually better.
Then this,
the
?
is a modifier on*
, making it lazy instead of the greedy default. Assuming PCRE.
I googled for PCRE
, but couldn't get what's the significance of this in my answer ?
and finally this,
I should also point out that this is regex (grep doing POSIX regex by default), not a shell glob.
I only know what a Regex is and very basic usage of it in grep command. So, I couldn't get any of those 3 comments and I have these questions in mind :
- What are differences in usage of
.*?
vs..*
? - Which is better and under what circumstance? Please provide examples.
Also It would be helpful to understand the comments, If anyone could
UPDATE: As an answer to question How are Regex different from Shell Globs ? @Kusalananda provided this link in his comment.
NOTE: If needed, Please read my answer to this question before answering for referring to the context.
.*
vs..*?
issue. The "difference between regular expressions and shell globs" question has already been addressed on this site. – Kusalananda May 05 '18 at 08:11