Posted by & filed under Uncategorized.

About caoyaming

Yaming Cao has written 16 post in this blog.

例如61.5.23.115,改为061.005.023.115

str = str.replaceAll("(\\d+)""00$1");
System.out.println(str);
//先在所有的数字组合前面加上2个0.
 
str = str.replaceAll("0*(\\d{3})""$1");
//保留后三位。
System.out.println(str);

One Response to “正则表达式在每个不足3位的IP地址前补0,以补齐3位。”

Leave a Reply

  • (will not be published)