| 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
|
 |
 |
|
|
subject: regExp matcher not working
|
|
|