Hi.
Ed Morton <address@hidden> wrote:
I just came across this in gawk 5.0.0 (note "4"):
1) $ echo 'foo{bar' | awk '/{/'
foo{bar
2) $ echo 'foo{bar' | awk --posix '/{/'
awk: cmd. line:1: error: Invalid preceding regular expression: /{/
3) $ echo 'foo{bar' | awk '/\{/'
foo{bar
4) $ echo 'foo{bar' | awk --posix '/\{/'
awk: cmd. line:1: warning: regexp escape sequence `\{' is not a
known regexp operator
foo{bar
I understand 1, 2, and 3 but I don't understand why I get the warning
from 4 above. I expected `\{` to simply be treated as a literal `{` with
no warnings just like other RE metachars are:
$ echo 'foo[bar' | awk --posix '/\[/'
foo[bar
$ echo 'foo+bar' | awk --posix '/\+/'
foo+bar
Instead I had to put it inside square brackets to get it treated as
literal with no warnings:
$ echo 'foo{bar' | awk --posix '/[{]/'
foo{bar
as no amount of additional preceding backslashes would make it "work"
without a warning:
$ echo 'foo{bar' | awk --posix '/\{/'
awk: cmd. line:1: warning: regexp escape sequence `\{' is not a
known regexp operator
foo{bar
$ echo 'foo{bar' | awk --posix '/\\{/'
$ echo 'foo{bar' | awk --posix '/\\\{/'
awk: cmd. line:1: warning: regexp escape sequence `\{' is not a
known regexp operator
$ echo 'foo{bar' | awk --posix '/\\\\{/'
$
Regards,
Ed.
The patch below fixes this.
Thanks for the report.
Arnold
-----------------------------------------------------------------
diff --git a/re.c b/re.c
index 174f54f8..210be068 100644
--- a/re.c
+++ b/re.c
@@ -107,7 +107,9 @@ make_regexp(const char *s, size_t len, bool ignorecase,
bool dfa, bool canfatal)
}
const char *ok_to_escape;
- if (do_traditional)
+ if (do_posix)
+ ok_to_escape = "{}()|*+?.^$\\[]/-";
+ else if (do_traditional)
ok_to_escape = "()|*+?.^$\\[]/-";
else
ok_to_escape = "<>`'BywWsS{}()|*+?.^$\\[]/-";