Artificial intelligent assistant

Pattern that includes literal [ and ] With the following `beg_ere` pattern, how can I have `(asmb)` enclosed by literal `[` and `]` ? #!/usr/local/bin/awk -f BEGIN { beg_ere = "^[[:space:]]*([#;!]+|@c|//)[[:space:]]+(faml) (asmb).*$" } $0 ~ beg_ere { print "MATCH" } Where `faml` and `asmb` are user defined strings, or if not user defined are described by `"[[:graph:]]+"`. In such case beg_ere = "^[[:space:]]*([#;!]+|@c|//)[[:space:]]+(faml) [([[:graph:]]+)]([[:space:]]*).*$" I am not getting MATCH being printed when use a file with the following lines ## HD [opcon] ## HD [opcon] key ## HD [opcon] akey,bkey where there can be any number of keys separated by commas.

You just need to escape them with backslashes.

However, because the regex is in a double quoted string, backslashes need to be escaped


beg_ere = "^[[:space:]]*([#;!]+|@c|//)[[:space:]]+(HD) \\[([[:graph:]]+)\\]([[:space:]]*).*$"
# .....................................................^^^..............^^^

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 6c7839ac992e39674d7d9b82f5257e32