Search code examples
javaregexlinuxnumbersspace

putting space between integer and '/' using regex in java


I have a String S= "grep -iRl 2020062312213461801003087/var/seamless/spool/tdr/Reconciliation" and i want to add space between last number and "/"

like i want my output to be grep -iRl 2020062312213461801003087 /var/seamless/spool/tdr/Reconciliation


Solution

  • Try this.

    String S= "grep -iRl 2020062312213461801003087/var/seamless/spool/tdr/Reconciliation";
    String replaced = S.replaceAll("(\\d)(/)", "$1 $2");
    System.out.println(replaced);
    

    result:

    grep -iRl 2020062312213461801003087 /var/seamless/spool/tdr/Reconciliation