Regular expressions

Tim Chase python.list at tim.thechases.com
Wed Nov 4 21:48:15 EST 2015


On 2015-11-05 13:28, Steven D'Aprano wrote:
> > I tried Tim's example
> > 
> > $ seq 5 | grep '1*'
> > 1
> > 2
> > 3
> > 4
> > 5
> > $  
> 
> I don't understand this. What on earth is grep matching? How does
> "4" match "1*"?

The line with "4" matches "zero or more 1s".  If it was searching for
a literal "1*" (as would happen with fgrep or "grep -F"), it would
return no results:

  $ seq 5 | fgrep '1*'
  $

-tkc






More information about the Python-list mailing list