regex - Need help understanding unexpected output from Java regular expression -
package com.j; public class program { public static void main(string[] args) { system.out.println(puzzel.class.getname().replaceall(".", "/") + ".class"); system.out.println(program.class.getname()); }
}
in above program expecting output com/j/program.class
but coming //////.class y?
in replacement, .
treated regular expression, .
means "any character" , here replaced /
, output becomes
////////////.class
for expected answer, change expression escape .
:
name.class.getname().replaceall("\\.", "/") + ".class");
then output expected:
com/j/puzzel.class
Comments
Post a Comment