Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > regular expression in java question

Reply
Thread Tools

regular expression in java question

 
 
Chen Yang
Guest
Posts: n/a
 
      10-05-2003
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


 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-05-2003
On Sun, 5 Oct 2003 17:01:52 -0400, "Chen Yang"
<zhenyoung.at.hotmail.com> wrote or quoted :

>
>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.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
 
Chen Yang
Guest
Posts: n/a
 
      10-05-2003
Hi,
Thanks a lot. Exactly, I am looking for \\(\\*. Now I understand. Thanks
again.

Roedy Green wrote:
> On Sun, 5 Oct 2003 17:01:52 -0400, "Chen Yang"
> <zhenyoung.at.hotmail.com> wrote or quoted :
>
>
>>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.
>
> --
> Canadian Mind Products, Roedy Green.
> Coaching, problem solving, economical contract programming.
> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments