bug-grep
[Top][All Lists]
Advanced

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

bug#72850: Can't match ] in [ ] regexp bug?


From: Khoa Ton
Subject: bug#72850: Can't match ] in [ ] regexp bug?
Date: Thu, 29 Aug 2024 00:53:10 -0700
User-agent: Mozilla Thunderbird

On 8/28/2024 1:32 AM, arnold@skeeve.com wrote:
Khoa Ton <khoa@puresynergy.com> wrote:

I'm on Ubuntu:

$ uname -a
Linux nile 5.15.0-118-generic #128-Ubuntu SMP Fri Jul 5 09:28:59 UTC 2024 
x86_64 x86_64 x86_64 GNU/Linux

I can't seem to get grep to match lines with ] in them when using [ ] 
expression.
grep only matches two characters string "\]" instead:

$ echo ']' | grep -E "[\]]" # supposed to return ] but doesn't
$ echo '\]' | grep -E "[\]]" # incorrectly matches '\]' but not ']'
\]

Possible grep bug:
grep doesn't seem to correctly handle escaped "\]" inside [ ] expressions.

Thank you,
Khoa

Grep doesn't support backslash escapes inside [...] (although awk does).

The correct way to do this is to place the ] as the first character
inside the [...], like so:

$ echo ] | grep -E '[]]'
]

HTH,

Arnold


Thank you.

Khoa





reply via email to

[Prev in Thread] Current Thread [Next in Thread]