![](/img/trans.png)
[英]How to extract the numbers with signage within the square bracket from the text file and store them in array (java)? Also, I want to exclude that 97
[英]To extract text from square bracket java regex
如何提取CardType中的文本:[.....]
CardType:[ CashRebate=[true], Platinum=[true], CoBrandCard=[true]{CoBrandType:Holt Renfrew}, ChargeCard=[true], ConsumerCard=[true], Product Type Code:null ]
最初我嘗試使用以下代碼
pattern p = Pattern.compile("CardType:\\[(.*?)\\]");
Matcher m = p.matcher(value);
我得到輸出為
CashRebate=[true
Platinum=[true
有人可以幫我嗎
謝謝
如果您希望輸出為:
CashRebate=[true], Platinum=[true], CoBrandCard=[true]{CoBrandType:Holt Renfrew}, ChargeCard=[true], ConsumerCard=[true], Product Type Code:null
只需使正則表達式變得不懶惰即可:
pattern p = Pattern.compile("CardType:\\[(.*)\\]");
Matcher m = p.matcher(value);
這使正則表達式匹配]
的最后一個實例。
嘗試這個:
pattern p = Pattern.compile("CardType:\\[\s(.*?)\s\\]");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.