java 正则表达式 如何匹配"*"?
比如说我想把Stringa="The*isa*.";中的*替换成另一个字符串"dog"a.replaceAll("*","dog");结果会报:Danglingmetac...
比如说我想把String a="The * is a *.";中的*替换成另一个字符串"dog"
a.replaceAll("*","dog");
结果会报:
Dangling meta character '*' near index 0
*
^
at java.util.regex.Pattern.error(Pattern.java:1713)
at java.util.regex.Pattern.sequence(Pattern.java:1878)
at java.util.regex.Pattern.expr(Pattern.java:1752)
at java.util.regex.Pattern.compile(Pattern.java:1460)
at java.util.regex.Pattern.<init>(Pattern.java:1133)
at java.util.regex.Pattern.compile(Pattern.java:823)
at java.lang.String.replaceAll(String.java:2189)
请问replaceAll中的regex该怎么写? 展开
a.replaceAll("*","dog");
结果会报:
Dangling meta character '*' near index 0
*
^
at java.util.regex.Pattern.error(Pattern.java:1713)
at java.util.regex.Pattern.sequence(Pattern.java:1878)
at java.util.regex.Pattern.expr(Pattern.java:1752)
at java.util.regex.Pattern.compile(Pattern.java:1460)
at java.util.regex.Pattern.<init>(Pattern.java:1133)
at java.util.regex.Pattern.compile(Pattern.java:823)
at java.lang.String.replaceAll(String.java:2189)
请问replaceAll中的regex该怎么写? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询