Regular expressions

Nobody nobody at nowhere.invalid
Wed Nov 4 00:05:53 EST 2015


On Wed, 04 Nov 2015 14:23:04 +1100, Steven D'Aprano wrote:

>> Its very name indicates that its default mode most certainly is regular
>> expressions.
> 
> I don't even know what grep stands for.

>From the ed command "g /re/p" (where "re" is a placeholder for an
arbitrary regular expression). Tests all lines ("g" for global) against
the specified regexp and prints ("p") any which match.

> But I think what Michael may mean is that if you "grep foo", no regex
> magic takes place since "foo" contains no metacharacters.

At least the GNU version will treat the input as a regexp regardless of
whether it contains only literal characters. I.e. "grep foo" and
"grep [f][o][o]" will both construct the same state machine then process
the input with it.

You need to actually use -F to change the matching algorithm.




More information about the Python-list mailing list