tags:

views:

2256

answers:

6

Hi!
I have been playing with JFlex and at this moment I want to get a regex that match a square bracket "[", but I don't find it. I think I tried all posivilities but the right.
Some help?

+5  A: 

How about using backslash (\) in front of the square bracket. Normally square brackets match a character class.

Peter Stuifzand
+1  A: 

did you tried \\[ or simply \[ ?

dfa
A: 

does it work with an antislash before the '[' ?

\[ or \\[ ?

Pierre
+1  A: 

Are you escaping it with "\"?

/\[/

Here's a helpful resource to get started with Regular Expressions:

Regular-Expressions.info

sirlancelot
A: 

In general, when you need a character that is "special" in regexes, just prefix it with a \. So a literal [ would be \[.

Zifre
A: 

If you're looking to find both variations of the square brackets at the same time, you can use the following pattern which defines a range of either the "[" sign or the "]" sign: /[\[\]]/

Jaytop