String replaceAll-正則匹配-截取以指定字符開頭,以指定字符結尾的字符串

scala代碼塊

截取以某個字符開頭,以某個字符結尾的字符串java

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
c1mspa

java代碼塊

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,escala

相關文章
相關標籤/搜索