Skip to content

awk: a / inside a bracket expression ends the regex literal #173

Open

Description

@sylvestre

Inside [...] a / is an ordinary character, so /a[/]b/ is a regex that
matches a/b. uutils awk ends the regex at the / inside the brackets and
then fails to parse the rest of the line. [/] is the usual way to match a
slash in paths (sub(/.*[/]/, "")).

Reproduction

Rust (incorrect)

$ ./target/release/awk 'BEGIN { print ("a/b" ~ /^a[/]b$/) }'
Error: Syntax error
   ╭─[ CLI:1:29 ]
 1 │ BEGIN { print ("a/b" ~ /^a[/]b$/) }
   │                             ╰── Missing closing parenthesis `(` in statement operand.

GNU (correct)

$ gawk 'BEGIN { print ("a/b" ~ /^a[/]b$/) }'
1

Test

#[test]
fn slash_in_regex_bracket() {
    ucmd()
        .arg("{ sub(/.*[/]/, \"\"); print }")
        .pipe_in("usr/share/doc\n")
        .succeeds()
        .stdout_only("doc\n");
}

Exposed by the GNU awk test suite: beginfile1, regexpbrack.

Activity

  1. added
    bug
    good first issue
    gnu-compat
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggnu-compatgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions