[vox-tech] regex help - matching literal []

Kenneth Herron kherron+lugod at fmailbox.com
Fri Apr 28 15:45:25 PDT 2006


Micah J. Cowan wrote:
> On Fri, Apr 28, 2006 at 04:19:34PM -0500, Ken Bloom wrote:
>> Target exception: java.util.regex.PatternSyntaxException: Unclosed 
>> character class near index 5
>> [[].*]
>>      ^
>>
>> java.util.regex.PatternSyntaxException: Unclosed character class near 
>> index 5
>> [[].*]
>>      ^
> 
> Then it violates POSIX regex syntax. That's a broken response, IMO.

I've been reading 
<http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html> 
and <http://www.opengroup.org/onlinepubs/007908799/xbd/re.html>, and 
perhaps I'm missing it but they don't seem to support your assertion. 
And of course google doesn't allow searching for punctuation. I'd 
appreciate it if you would explain how "[[].*]" is valid, or point to 
some source that supports your position.

Besides which, Peter was trying to match "[" and "]" individually. A 
single RE that matches either character isn't what he wanted. Does 
"[[].*]" match "[" or "]"?

ObAlternateSolution: the expression "[[]" matches "[", "[]]" matches 
"]", and "[[][]]" matches "[]".


More information about the vox-tech mailing list