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