[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: --only-match
From: |
Daiki Ueno |
Subject: |
Re: --only-match |
Date: |
09 May 2001 10:03:20 +0900 |
User-agent: |
T-gnus/6.15.3 (based on Oort Gnus v0.03) |
>>>>> In <address@hidden>
>>>>> Paul Eggert <address@hidden> wrote:
> If I understand it correctly, the proposed code prints just the first
> match in each line. This doesn't sound right to me: it should print
> each match that it finds. This raises the issue of whether it should
> print overlapping matches; presumably it should. It also raises the
> issue of how many empty strings occur in a file: presumably it's only
> one per input character, as otherwise 'grep' would loop.
What about moving right one character even if the matching string is
empty?
while ((match_offset = (*execute) (beg, lim - beg, &match_size, 1))
!= (size_t) -1)
{
char const *b = beg + match_offset;
/* Avoid matching the empty line at the end of the buffer. */
if (b == lim)
break;
/* ... */
/* If the matching string is empty, skip one character. */
if (match_size < 1)
match_size = 1;
beg = b + match_size;
}
It seems to work for me :-)
$ cat test.txt
aaatestaaatestbbb
abatestbaa
$ grep --matching-string --color '[ab]*' test.txt
aaaaaabbb
ababaa
Regards,
--
Daiki Ueno