[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Grep colors highlight all possible matches

From: Pollock, Wayne
Subject: Grep colors highlight all possible matches
Date: Sat, 9 Feb 2013 23:28:47 +0000
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2

In teaching REs, I use grep and recently noticed
the colors highlight all possible matches, not
the one match as per POSIX's rules:

  echo 'abcdefabc' | grep '[abc]'

Should highlight only the first "a" (earliest match has
precedence, than longest).  Instead, every "a", "b", and
"c" is highlighted.  It would be my guess that grep historically
didn't need to know exactly what matched, just that something
did, so the code doesn't bother to apply any rules to determine
exactly what matched.

I don't mind the current behavior as a default, but there should
be some option to force grep to only highlight the one match,
as per BRE/ERE/PCRE rules of precedence.

Wayne Pollock
Please Note: 

Due to Florida's very broad public records law, most written communications to
or from College employees regarding College business are public records,
available to the public and media upon request.  Therefore, this email
communication may be subject to public disclosure.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]