我有一個包含以下格式的搜索字符串:正則表達式模式
搜索字符串
111651311
111651303
4111650024
4360280062
20167400
它需要與數字的順序相匹配低於
001111651311000
001111651303000
054111650024000
054360280062000
201674000000000
請注意搜索字符串已在每邊添加了附加數字。 我在java中嘗試過下面的正則表達式來匹配搜索字符串,但它只適用於一些。
Pattern pattern = Pattern.compile("([0-9])\1*"+c4MIDVal+"([0-9])\1*");
有什麼建議嗎?
更新
加我下面使用可能會提供什麼我試圖做
代碼段
public void compare(String fileNameAdded, String fileNameToBeAdded){
List<String> midListAdded = readMID.readMIDAdded(fileNameAdded);
HashMap<String, String> midPairsToBeAdded = readMID.readMIDToBeAdded(fileNameToBeAdded);
List <String []> midCaptured = new ArrayList<String[]>();
for (Map.Entry<String, String> entry: midPairsToBeAdded.entrySet()){
String c4StoreKey = entry.getKey();
String c4MIDVal = entry.getValue();
Pattern pattern = Pattern.compile("([0-9]?)\\1*"+c4MIDVal+"([0-9]?)\\2*");
for (String mid : midListAdded){
Matcher match = pattern.matcher(mid);
// logger.info("Match Configured MID :: "+ mid+ " with Pattern "+"\\*"+match.toString()+"\\*");
if (match.find()){
midCaptured.add(new String []{ c4StoreKey +"-"+c4MIDVal, mid});
}
}
}
logger.info(midCaptured.size()+ " List of Configured MIDs ");
for (String [] entry: midCaptured){
logger.info(entry[0]+ "- "+entry[1] );
}
}
'indexOf'不足夠嗎? – Berger
或'contains'。吻。 – NickJ
我已經包含了我的代碼,請檢查 – dimas