Results 1 to 2 of 2
Thread: pattern matcher problem
- 04-02-2010, 02:03 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 4
- Rep Power
- 0
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(ss);
while(b=m.find())
{
System.out.println("match :"+m.group());
}
}
}
//
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..
- 04-02-2010, 02:55 AM #2
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
-
Problem with observer pattern
By livnihai in forum New To JavaReplies: 5Last Post: 10-11-2009, 02:34 PM -
Pattern
By mtyoung in forum Advanced JavaReplies: 9Last Post: 04-07-2009, 02:17 AM -
Regex Pattern/Matcher - Print only one occurrence!
By racha0601 in forum Advanced JavaReplies: 3Last Post: 04-06-2009, 05:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks