java正則表達(dá)式匹配所有數(shù)字的案例
用于匹配的正則表達(dá)式為 :([1-9]d*.?d*)|(0.d*[1-9])
(
[1-9] :匹配1~9的數(shù)字;
d :匹配數(shù)字,包括0~9;
* :緊跟在 d 之后,表明可以匹配零個(gè)及多個(gè)數(shù)字;
. :匹配小數(shù)點(diǎn);
? :緊跟在 . 之后,表明可以匹配零個(gè)或一個(gè)小數(shù)點(diǎn);
0 :匹配一個(gè)數(shù)字0;
)
其中的 [1-9]d*.?d* 用以匹配諸如:1、23、34.0、56.78 之類的非負(fù)的整數(shù)和浮點(diǎn)數(shù);
其中的 0.d*[1-9] 用以匹配諸如:0.1、0.23、0.405 之類的非負(fù)浮點(diǎn)數(shù);
private List GetTmpFieldsList(List FieldsList,String tmptableName,String IndexName) { List maps = new ArrayList<>(); for(String field :FieldsList){ //必須包含傳入的標(biāo)識(shí)符,同時(shí)要包含數(shù)字 if(field.toLowerCase().contains(tmptableName.toLowerCase())){ FieldList e = new FieldList(); String [] fieldArray = field.split('.');//帶數(shù)字的string field = field.replaceAll('_?d+', ''); //去掉下劃線加數(shù)字 得有效的物理名 String [] fieldArray2 = field.split('.'); //不帶數(shù)字的string Pattern p = Pattern.compile('d+'); //得到字符串中的數(shù)字 Matcher m = p.matcher(fieldArray[1]); if(m.find()){ int key = Integer.parseInt(m.group()); e.setCaseValue(key); if(StringUtils.isEqual(fieldArray2[1], IndexName)){ //for BAT203 e.setField('CHECK_POSITION'); //?目物理名 }else{ e.setField(fieldArray2[1]); //?目物理名 } e.setFieldName(fieldArray[1]); //?目物理名?e名 maps.add(e); } /**else{ 只有后面帶數(shù)字的才可以 if(StringUtils.isEqual(fieldArray2[1],IndexName)){ //for BAT203 e.setField('CHECK_POSITION'); //?目物理名 }else{ e.setField(fieldArray2[1]); } e.setFieldName(fieldArray[1]); maps.add(e); }**/ } } //Add ACE商品マスタ.更新フラグ return maps; }
補(bǔ)充知識(shí):關(guān)于fasterxml-jackson發(fā)生Can not deserialize instance of異常原因驗(yàn)證
這兩天線上有大量的
java.lang.IllegalArgumentException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
at [Source: N/A; line: -1, column: -1]錯(cuò)誤發(fā)生。
有經(jīng)驗(yàn)的人一看,就知道是對(duì)象屬性轉(zhuǎn)換發(fā)生異常了。為了把這個(gè)錯(cuò)誤的根本原因找到。
只能上代碼模擬了。
/** * Created by changle on 17/1/9. */@Slf4jpublic class JSONTest { public static void main(String[] args) { testAtoB(); //testAtoB() 發(fā)生:Can not deserialize instance of com.test.JSONTest$Hobby out of START_ARRAY token testBtoA(); //testBtoA() 發(fā)生:Can not deserialize instance of java.util.ArrayList out of START_OBJECT token } public static void testAtoB(){ List<Hobby> hobbies = new ArrayList<>(); Random random = new Random(); for(int i=0;i<3;i++){ Hobby hobby = new Hobby(random.nextInt(),'測試名稱','測試類型',random.nextInt(100)); hobbies.add(hobby); } StudentA studentA = new StudentA(); studentA.setAge(23); studentA.setFromCity(true); studentA.setMoney(3000); studentA.setName('張三'); studentA.setHobbies(hobbies); try { String str = JSON.json(studentA); log.info('str={}',str); //list轉(zhuǎn)換單個(gè)projo StudentB studentB = JsonUtil.jsonObject(str, StudentB.class); log.info('studentB.name:{}',studentB.getName()); } catch (Exception e) { e.printStackTrace(); } } public static void testBtoA(){ Random random = new Random(); Hobby hobby = new Hobby(random.nextInt(), '測試名稱', '測試類型', random.nextInt(100)); StudentB studentB2 = new StudentB(); studentB2.setAge(23); studentB2.setFromCity(true); studentB2.setMoney(3000); studentB2.setName('張三'); studentB2.setHobbies(hobby); String str2 = null; try { str2 = JSON.json(studentB2); //單個(gè)projo轉(zhuǎn)換list StudentA studentA2 = JsonUtil.jsonObject(str2, StudentA.class); log.info('studentB.name:{}', studentA2 == null ? '' : studentA2.getName()); } catch (IOException e) { e.printStackTrace(); } } @Data public static class StudentA{ private String name; private int age; private long money; private boolean isFromCity; private List<Hobby> hobbies; } @Data public static class StudentB{ private String name; private int age; private long money; private boolean isFromCity; private Hobby hobbies; } @Data public static class Hobby{ private long hId; private String hName; private String type; private int score; public Hobby(){} public Hobby(long hId,String hName,String type,int score){ this.hId = hId; this.hName = hName; this.type = type; this.score = score; } }}
結(jié)論:
Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
該錯(cuò)誤是因?yàn)槟繕?biāo)類屬性keyX需要ArrayList類型的,待轉(zhuǎn)換的json串里屬性名keyX對(duì)應(yīng)的,不是一個(gè)ArrayList集合,而是單個(gè) POJO。
Can not deserialize instance of com.test.JSONTest$Hobby out of START_ARRAY token
該錯(cuò)誤是因?yàn)槟繕?biāo)類屬性keyX需要JSONTest$Hobby類型的,待轉(zhuǎn)換的json串里屬性名keyX對(duì)應(yīng)的,不是一個(gè)POJO對(duì)象,而是ArrayList集合。
以上這篇java正則表達(dá)式匹配所有數(shù)字的案例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. JavaWeb Servlet中url-pattern的使用2. 淺談SpringMVC jsp前臺(tái)獲取參數(shù)的方式 EL表達(dá)式3. asp(vbscript)中自定義函數(shù)的默認(rèn)參數(shù)實(shí)現(xiàn)代碼4. React優(yōu)雅的封裝SvgIcon組件示例5. 輕松學(xué)習(xí)XML教程6. php網(wǎng)絡(luò)安全中命令執(zhí)行漏洞的產(chǎn)生及本質(zhì)探究7. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)8. jsp中sitemesh修改tagRule技術(shù)分享9. ASP基礎(chǔ)知識(shí)VBScript基本元素講解10. 詳解瀏覽器的緩存機(jī)制
