regular expression in java question

Discussion in 'Java' started by Chen Yang, Oct 5, 2003.

  1. Chen Yang

    Chen Yang Guest

    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
     
    Chen Yang, Oct 5, 2003
    #1
    1. Advertising

  2. Chen Yang

    Roedy Green Guest

    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.
     
    Roedy Green, Oct 5, 2003
    #2
    1. Advertising

  3. Chen Yang

    Chen Yang Guest

    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.
     
    Chen Yang, Oct 5, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,390
  2. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    884
    Alan Moore
    Dec 2, 2005
  3. GIMME
    Replies:
    3
    Views:
    12,050
    vforvikash
    Dec 29, 2008
  4. joes
    Replies:
    2
    Views:
    1,065
    Daniel Pitts
    May 25, 2007
  5. NeoGeoSNK
    Replies:
    4
    Views:
    3,744
    Joshua Cranmer
    Mar 3, 2008
Loading...

Share This Page