What does [[]] mean in regex?
$ echo '[][]' | grep -oE '[[]]'
[]
[]
$ grep --version
grep (GNU grep) 2.10
Hmm, it appear that it matches [].
(The character sequences [], not [ or ].)
(I’ve tested it with python’s re module, same result.)
Really?
If so, why?
I knew if I want to match [ or ], I should have written [][] or [[\]].
(They work in PCRE, grep supports [][] but not [[\]] since \ loses special meaning in grep’s bracket expression.)
I’m only feeling curiosity.
The expression
[[]]actually consists of two concatenated subexpressions:[[]and].[[]is character class that matches only[characters. Having[is only possible at the very beginning of a character class.]is just a normal character if outside of a character class.Both are concatenated thus your expression matches any character of
[followed by], which results in matching[].