java replaceall a= a.replaceAll("(^|\\.)(\\d)(\\.|$)","$100$2$3");a= a.replaceAll("(^|\\.)(\\d)(\\.|$)","$100$2$3");a= a.replaceAll("(^|\\.)(\\d{2})(\\.|$)","$10$2$3");a.replaceAll("(^|\\.)(\\d{2})(\\.|$)","$10$2$3");

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/17 13:52:00

java replaceall a= a.replaceAll("(^|\\.)(\\d)(\\.|$)","$100$2$3");a= a.replaceAll("(^|\\.)(\\d)(\\.|$)","$100$2$3");a= a.replaceAll("(^|\\.)(\\d{2})(\\.|$)","$10$2$3");a.replaceAll("(^|\\.)(\\d{2})(\\.|$)","$10$2$3");
java replaceall
a= a.replaceAll("(^|\\.)(\\d)(\\.|$)","$100$2$3");
a= a.replaceAll("(^|\\.)(\\d)(\\.|$)","$100$2$3");
a= a.replaceAll("(^|\\.)(\\d{2})(\\.|$)","$10$2$3");
a.replaceAll("(^|\\.)(\\d{2})(\\.|$)","$10$2$3");

java replaceall a= a.replaceAll("(^|\\.)(\\d)(\\.|$)","$100$2$3");a= a.replaceAll("(^|\\.)(\\d)(\\.|$)","$100$2$3");a= a.replaceAll("(^|\\.)(\\d{2})(\\.|$)","$10$2$3");a.replaceAll("(^|\\.)(\\d{2})(\\.|$)","$10$2$3");
a= a.replaceAll("(^|\\.)(\\d)(\\.|$)", "$100$2$3");
"(^|\\.)(\\d)(\\.|$)" 这个正则表达式被用小括号分成了三部分.
$1就代表第一部分(^|\\.)匹配的内容,
$2就代表第二部分(\\d)匹配的内容,
$3就代表第三部分(\\.|$)匹配的内容,
"$100$2$3" 就是$1+00+$2+$3 .$1,$2,$3是变量
例如:
a="111.2.33.44";
a= a.replaceAll("(^|\\.)(\\d)(\\.|$)", "$100$2$3");
结果就是:111.002.33.4
(^|\\.)(\\d)(\\.|$) 匹配到的是.2.
这时候:
$1=.
$2=2
$3=.
"$100$2$3" 就是 $1+00+$2+$3=.+00+2+. 就是.002.
结果就把.2.替换为.002.了.

其他的表达式雷同.