I'm trying to match an ampersand, but haven't been able to figure out how to do so, even after searching the forum and the wider Internet through Google. I understand that a double-ampersand is used as an intersection operator in the regular expressions, but my understanding is that a single ampersand should be considered literal. I am running JDK 1.6.0 update 25 on the Linux x64 platform (build 1.6.0_25-b06). The following illustrates my trouble:
$ cat Test.java
public class Test
{
public static void main(String[] args)
{
System.out.println("select &hi from dual".matches("&"));
System.out.println("select &hi from dual".matches("\u0026"));
System.out.println("select &hi from dual".matches("\\&"));
System.out.println("select &hi from dual".matches("&&"));
}
}
$ javac Test.java
$ java Test
false
false
false
false
$
How can I match this?