用户可以输入任何字符串字符,唯一允许的特殊字符是*,可以放在字符串的开头或结尾。
例如:
*hello* -> *hello
*h*ello -> *hello
h*llo* -> hello*
hello** -> hello*
**hell**o** -> *hello
我喜欢有正则表达式。
答案 0 :(得分:1)
这个以某种方式工作
String s="*he**llo*";//anything
boolean st=(s.startsWith("*"));
boolean et=(s.endsWith("*"));
String ns=s.replaceAll("\\*+","");
ns=(st)?("*"+ns):(et)?(ns+"*"):ns;
答案 1 :(得分:1)