欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java正則表達(dá)式獲取大括號(hào)小括號(hào)內(nèi)容并判斷數(shù)字和小數(shù)親測(cè)可用

 更新時(shí)間:2019年06月26日 09:58:05   作者:xuxie13  
這篇文章主要介紹了java正則表達(dá)式獲取大括號(hào)小括號(hào)內(nèi)容并判斷數(shù)字和小數(shù)親測(cè)可用,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

 獲取大括號(hào)小括號(hào)內(nèi)容

項(xiàng)目開(kāi)發(fā)用到了,暫做個(gè)簡(jiǎn)單記錄

private static String regex = "\\{([^}]*)\\}";//匹配大括號(hào)
 private static String regexx = "\\(([^}]*)\\)";//匹配小括號(hào)
 public static void main(String[] args) {
 String dakuohao = "{a+b}={c+d}>vvxyksv9kd";
 Pattern compile = Pattern.compile(regex);
 Matcher matcher = compile.matcher(dakuohao);
 while(matcher.find()){
 String group = matcher.group();
 System.out.print(group+";");
 }
 
 System.out.println();
 
 String xiaokuohao = "(a+b)=(c+d)>(d)";
 Pattern comp = Pattern.compile(regex);
 Matcher mat = comp.matcher(dakuohao);
 while(mat.find()){
 String group = mat.group();
 System.out.print(group+";");
 }
 }

匹配大括號(hào)和小括號(hào)的表達(dá)式,只有轉(zhuǎn)義后面的符號(hào)變了,是不是也可以換成別的

對(duì)稱(chēng)的符號(hào)呢

在這里插入圖片描述

判斷數(shù)字或者小數(shù)或數(shù)字小數(shù)混合

整數(shù)      ^([0-9]{1,}[.][0-9]*)$

在這里插入圖片描述

小數(shù)   ^([0-9]{1,}[.][0-9]*)$

測(cè)試的時(shí)候我也找了不少博客,感覺(jué)多數(shù)人的都不能避免數(shù)字中的特殊符號(hào)

在這里插入圖片描述

小數(shù)和數(shù)字混合    (^[0-9]*$)|(^([0-9]{1,}[.][0-9]*)$)

在這里插入圖片描述

ps:java使用正則表達(dá)式提取小括號(hào)中的內(nèi)容

public class Test {
  public static List<String> getMsg(String msg) {

  List<String> list = new ArrayList<String>();
   Pattern p = Pattern.compile("(\\()([0-9a-zA-Z\\.\\/\\=])*(\\))");
   Matcher m = p.matcher(msg);
   while (m.find()) {
    list.add(m.group(0).substring(1, m.group().length() - 1));
   }
   return list;
  }

 public static void main(String[] args) throws Exception {
   String msg = "mSurface=Surface(name=com.bbk.launcher2/com.bbk.launcher2.Launcher)";
   List<String> list = getMsg(msg);
   System.out.println(list);
  }
 }

總結(jié)

以上所述是小編給大家介紹的java正則表達(dá)式獲取大括號(hào)小括號(hào)內(nèi)容并判斷數(shù)字和小數(shù)親測(cè)可用,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

最新評(píng)論