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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -