美文网首页
Java 正则表达式 截取字符串

Java 正则表达式 截取字符串

作者: 泛空秋慕 | 来源:发表于2018-08-22 15:11 被阅读0次

    1. 2018-08-20 从异常信息中截取失败的原因

    • 需求:从如下异常信息中取出导致失败的数据列值,需要匹配的字符(示例)为(batch_no, order_id, payment_model)=(20180819043, APK9275585443, 交易退款)
    ### Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "pk_c_alipay_original_data"
      详细:Key (batch_no, order_id, payment_model)=(20180819043, APK9275585443, 交易退款) already exists.
    ; SQL []; ERROR: duplicate key value violates unique constraint "pk_c_alipay_original_data"
      详细:Key (batch_no, order_id, payment_model)=(20180819043, APK9275585443, 交易退款) already exists.; nested exception is org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "pk_c_alipay_original_data"
      详细:Key (batch_no, order_id, payment_model)=(20180819043, APK9275585443, 交易退款) already exists.
    
    • 正则及截取如下:
     String regexp = "\\(batch_no, order_id, payment_model\\)=\\(.*\\)";
     Pattern pattern = Pattern.compile(regexp);
     Matcher matcher = pattern.matcher(msg);
     if (matcher.find()) {
        System.out.println(matcher.group(0));
     }
    

    相关文章

      网友评论

          本文标题:Java 正则表达式 截取字符串

          本文链接:https://www.haomeiwen.com/subject/omhyiftx.html