[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: grep: echo -en "AB\nA B\n" | egrep 'A?B'
From: |
John Cowan |
Subject: |
Re: grep: echo -en "AB\nA B\n" | egrep 'A?B' |
Date: |
Fri, 14 Dec 2007 12:13:36 -0500 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
p.p. scripsit:
> if I do
>
> echo -en "AB\nA B\n" | egrep 'A?B'
>
> the result is
> AB
> A B
>
> while, as I understand it, the second line containing the space should not
> match.
>
> Is this a bug in grep or in my understanding of regular expressions?
The latter.
Your pattern says to match an optional A followed by a B. The first
line has an A followed by a B, so it matches; the second line has a B,
so it too matches. The presence of an A on the second line is irrelevant.
You may want to wrap your pattern in ^ and $ to force it to match the
whole line.
--
Using RELAX NG compact syntax to John Cowan <address@hidden>
develop schemas is one of the simple http://www.ccil.org/~cowan
pleasures in life....
--Jeni Tennison <address@hidden>