If you have a look at the awk
source code, you can see that illegal primary is a default FATAL
error when none of the cases for the regex tokens matched. It is not a Syntax Error.
Here is the specific code from b.c
file of awk (stripped),
case NCCL:
np = op2(NCCL, NIL, (Node *) cclenter((char *) rlxstr));
rtok = relex();
return (unary(np));
case '^':
rtok = relex();
return (unary(op2(CHAR, NIL, itonp(HAT))));
case '$':
rtok = relex();
return (unary(op2(CHAR, NIL, NIL)));
case '(':
rtok = relex();
if (rtok == ')') { /* special pleading for () */
rtok = relex();
return unary(op2(CCL, NIL, (Node *) tostring("")));
}
np = regexp();
if (rtok == ')') {
rtok = relex();
return (unary(np));
}
else
FATAL("syntax error in regular expression %s at %s", lastre, prestr);
default:
FATAL("illegal primary in regular expression %s at %s", lastre, prestr);
This code is also available on github here,
https://github.com/onetrueawk/awk/blob/master/b.c
in your specific case the reason is because Lookarounds, i.e, Lookahead: (?=...), (?!...)
and Lookbehind: (?<=...), (?<!...)
are not supported by awk.
Hope this helps