Two backslashes before the open and close brackets: \\[
and \\]
The double backslash evaluates a single backslash in the string. The single backslash escapes the brackets so that they are not interpreted as surrounding a character class.
No backslashes for the brackets that do declare the character class: [a-z]
(you can you any range you like, not just a to z)
The Kleene star operator matches any number of characters in the range.
public class Regexp {
public static void main(final String... args) {
System.out.println("[action]".matches("\\[[a-z]*\\]"));
}
}
On my system:
$ javac Regexp.java && java Regexp
true