您可以使用下面的代碼這從字符串
private void extractMerchantNameFromSMS(){
try{
String mMessage= "Dear Customer, You have made a Debit Card purchase of INR1,600.00 on 30 Jan. Info.VPS*AGGARWAL SH.";
Pattern regEx = Pattern.compile("(?i)(?:\\sInfo.\\s*)([A-Za-z0-9*]*\\s?-?\\s?[A-Za-z0-9*]*\\s?-?\\.?)");
// Find instance of pattern matches
Matcher m = regEx.matcher(mMessage);
if(m.find()){
String mMerchantName = m.group();
mMerchantName = mMerchantName.replaceAll("^\\s+|\\s+$", "");//trim from start and end
mMerchantName = mMerchantName.replace("Info.","");
FileLog.e(TAG, "MERCHANT NAME : "+mMerchantName);
}else{
FileLog.e(TAG, "MATCH NOTFOUND");
}
}catch(Exception e){
FileLog.e(TAG, e.toString());
}
}
獲取商戶名稱感謝@VikalpPatel其作品.. –