aspose file tools
The moose likes Java in General and the fly likes regExp matcher not working Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "regExp matcher not working" Watch "regExp matcher not working" New topic
Author

regExp matcher not working

ketandba shah
Greenhorn

Joined: Feb 05, 2005
Posts: 22
hi,
here is my java code snippet..

String REGEX = "(d*-d*-d*)";
String INPUT = "(some string)|(d*-d*-d*)";
String REPLACE = "(\\\\\\\\d*-\\\\\\\\d*-\\\\\\\\d*)";

Pattern p = Pattern.compile(REGEX);
Matcher m = p.matcher(INPUT); // get a matcher object
INPUT = m.replaceAll(REPLACE);
System.out.println(INPUT);

This not works....what is wrong in REGEXP...

i am expecting output as (some string)|(\\d*-\\d*-\\d*)

Thanks in advanced...

ketan
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
In a regex, * is a special character. If you want it to represent a literal * rather than its meaning as a special character, you need to escape it with \\. So your REGEX should be

String REGEX = "(d\\*-d\\*-d\\*)";


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: regExp matcher not working
 
Similar Threads
Extracting numbers from a String using regular expressions
Regular expression to take integers out of a string
Regular expression
matching a string in a line
What ?: does in the regular expression (?:\w*?)?