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

Ken Bloom kbloom at gmail.com
Fri Apr 28 14:19:34 PDT 2006


On Friday 28 April 2006 16:05, Micah J. Cowan wrote:
> On Fri, Apr 28, 2006 at 01:25:41PM -0700, Rod Roark wrote:
> > On Friday 28 April 2006 01:07 pm, Peter Jay Salzman wrote:
> > ...
> >
> > > However, the compiler complains when I escape the square brackets
> > > with a backslash.  For some reason \[ doesn't match a literal [.
> >
> > Sounds like you need to double up on the backslashes -- once for
> > the compiler's parsing of string literals, and once for the regex
> > parser.
>
> You could also use "[[].*]".

Hrm? I don't think so. 

[bloom at cat-in-the-hat ~]$ bsh
BeanShell 2.0b4 - by Pat Niemeyer (pat at pat.net)
bsh % System.out.println("[ioaudsoif]".matches("[[].*]"));
// Error: // Uncaught Exception: Method Invocation matches : at Line: 
1 : in file: <unknown file> : .matches ( "[[].*]" ) 

Target exception: java.util.regex.PatternSyntaxException: Unclosed 
character class near index 5
[[].*]
     ^

java.util.regex.PatternSyntaxException: Unclosed character class near 
index 5
[[].*]
     ^


-- 
I usually have a GPG digital signature included as an attachment.
See http://www.gnupg.org/ for info about these digital signatures.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://ns1.livepenguin.com/pipermail/vox-tech/attachments/20060428/eedca3e7/attachment.pgp


More information about the vox-tech mailing list