[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: match across line using grep



On 2010年08月04日 00:57, Bob McGowan wrote:
>  I would suspect
> the regex engine is still honoring '. (dot) does not match newline'
> convention but is OK with literals, if present.
>   

It can be a bug in grep implementation.

If your theory holds true, the following should match, but it doesn't.
$ printf "a\nb" | grep -z 'a[^a]*b'
$

Because, if dot does not match newline, like in Java (verified in
Java-based JEdit editor), then dot is equal to

[^\n]

In that case a easy way to workaround it is to replace dot with

[^[:something-horribly-non-existent:]]

P.S. A interesting design might be: for an RE implementation where dot
does not match newline, the very RE implementation should allow [^] to
mean really "matches anything". But the java people didn't do so, they
introduced "DOTALL" mode, if you enter this mode, dot means anything,
otherwise it means [^\n]. This new mode only makes things more
complicated to my understanding.


Reply to: