Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2010
    Rep Power

    Default pattern matcher problem

    import java.util.regex.*;
    class test034
    public static void main(String[] args)

    String s="abd sduasdrnsab1dab5";
    String p="\\w\\d";
    Pattern pp=Pattern.compile(p);
    Matcher m=pp.matcher(s);
    boolean b=false;
    //String ss=m.replaceAll("0");
    System.out.println("match :";


    if I remove the comments then the the while lop does not print any thing..,,..
    but the replaceAll method is not changing the original string but returning a new modified string.
    please help..

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Rep Power


    Look at the API. The replaceAll() method is resetting the state of any matching. This may very well be the expected behavior.
    The Java Tutorial. Read it.

Similar Threads

  1. Problem with observer pattern
    By livnihai in forum New To Java
    Replies: 5
    Last Post: 10-11-2009, 02:34 PM
  2. Pattern
    By mtyoung in forum Advanced Java
    Replies: 9
    Last Post: 04-07-2009, 02:17 AM
  3. Regex Pattern/Matcher - Print only one occurrence!
    By racha0601 in forum Advanced Java
    Replies: 3
    Last Post: 04-06-2009, 05:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts