scala代码块
截取以某个字符开头,以某个字符结尾的字符串
def main(args: Array[String]): Unit = {
val s = "{{a61,a2,a3},{b1,b2,b3},{c1m,.,kkl,c2,c3}}"
val reg = Pattern.compile("\\{(\\w+?),")
val matcher = reg.matcher(s)
while (matcher.find()) {
println(matcher.group(1))
}
}
运行结果
a61
b1
c1m
java代码块
public static void main(String[] args) {
test t = new test();
String a = "a+-b+ -c+ -d -e";
System.out.println(a);
System.out.println(a.replaceAll("(-|\\+| )",","));
}
运行结果
a±b+ -c+ -d -e
a,b,c,d,e