regular expression in java question

C

Chen Yang

Hi there,

How can i make the Pattern.compile as character '*' and '(' ?
I check the API, and it says:

\cx The control character corresponding to x

And if I write like this:

Pattern p1 = Pattern.compile(".*\\b\\c(\\c*\\b.*");
Matcher m1 = p1.matcher("(* ");
System.out.println(m1.find());


It returns false. Plez help me out with this, thanks in advance.

Chen
 
R

Roedy Green

How can i make the Pattern.compile as character '*' and '(' ?
I check the API, and it says:

You mean you want * and ( treated as literal characters rather than as
magic Regex commands, right?

You must precede them with a \. Since \ has magic meaning in Java
Strings, it must be doubled. So you would say \\* or \\(

See http://mindprod.com/jgloss/regex.html for more details.
 
C

Chen Yang

Hi,
Thanks a lot. Exactly, I am looking for \\(\\*. Now I understand. Thanks
again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top