正規表現特定のIDの文字列を取得して置換


正規式は特定の識別文字列を取得し、
処理対象文字列:#applyCom#は、「#applyNo#」という番号の「#applyType#」の件について、決済確認を申請しました.システムにログインして処理を確認してください.
ここではプレースホルダとして#*#の形式を用い,処理が必要な場所を示す.
正規処理コードを使用するには、次の手順に従います.
String content = "#applyCom#       “#applyNo#” “#applyType#”        。           。"; 

  //         , map          
  HashMap<String , String> map = new HashMap<String, String>();
  map.put("applyCom", "a");
  map.put("applyType", "b");
  map.put("applyNo", "c");
  

Pattern pat = Pattern.compile("(#[^#]*#)");//     

  Matcher mat = pat.matcher(content);
  int i = 0;
  while (mat.find()) {//     

   String temp = mat.group(1).toString().substring(1, mat.group(1).toString().length()-1);//     , :#applyCom#     applyCom

  content = content.replace(mat.group(1), map.get(temp));// map    ,       

   i++;
  }
  System.out.println(content);//