[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Question] Is this a bug?
From: |
Wolfgang Laun |
Subject: |
Re: [Question] Is this a bug? |
Date: |
Sat, 8 Jul 2023 10:34:33 +0200 |
grep with -P mimics Perl down to the least detail, i.e., the way Perl
parses any input text. Thus, '\x5B' is not the same as '[' but is treated
as '\[", an escaped bracket. Deep in the Perl 5 documentation on backslash
in regular expressions you can find this paragraph: *Note that a character
expressed as one of these* [hexadhecimal] *escapes is considered a
character without special meaning by the regex engine, and will match "as
is". *(There is a similar paragraph on octal escapes.)
(g)awk processes string literals and literal regular expressions as most
compilers do, converting hexadecimal escapes to characters. Therefore,
"\x5B" becomes "[" and is indistinguishable from a "[" in the input.
Wolfgang
On Fri, 7 Jul 2023 at 22:37, Sedapnya Tidur <sedapnyatidur@gmail.com> wrote:
> $ gawk 'BEGIN { print match("a[", /^[^[]\x5B/) }'
> gawk: cmd. line:1: error: Invalid regular expression: /^[^[]\/
>
> $ gawk -V
> GNU Awk 5.2.2, API 3.2, (GNU MPFR 4.2.0-p9, GNU MP 6.2.1)
>
> $ grep -Po --color '^[^[]\x5B' <<< 'a[xxx'
> a[
>
--
Wolfgang Laun