I can use Bash to match a set of characters
$ [[ a =~ [abc] ]]; echo $?
0
However if I want a close square bracket ]
to be included in the set, it fails
$ [[ a =~ [abc\]] ]]; echo $?
1
$ [[ a =~ [abc\\]] ]]; echo $?
1
From the man page regex(7)
:
To include a literal ']' in the list, make it the first character (fol-
lowing a possible '^').
Testing:
$ [[ "]" =~ []abc] ]]; echo $?
0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With