Regular expressions

Steven D'Aprano steve at pearwood.info
Wed Nov 4 21:28:49 EST 2015


On Wed, 4 Nov 2015 07:57 pm, Peter Otten 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*"?


> which surprised me because I remembered that there usually weren't any
> matching lines when I invoked grep instead of egrep by mistake. So I tried
> another one
> 
> $ seq 5 | grep '[1-3]+'
> $
> 
> and then headed for the man page. Apparently there is a subset called
> "basic regular expressions":
> 
> """
>   Basic vs Extended Regular Expressions
>        In basic regular expressions the meta-characters ?, +, {, |, (,
>        and ) lose their special meaning; instead use  the  backslashed
>        versions \?, \+, \{, \|, \(, and \).
> """

None of this appears relevant, as the metacharacter * is not listed. So
what's going on?




-- 
Steven




More information about the Python-list mailing list