Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Matching Ampersand in Regular Expression

542539May 19 2011 — edited May 19 2011
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?
This post has been answered by 796440 on May 19 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 16 2011
Added on May 19 2011
5 comments
5,215 views