the different dash punctuations to basic

the correct regex for replacing em-dash with a basic “-” in java

distinguish the different three dash punctuations '- – —' to transfer to basic '-'

- en dash(normal)

– macron

— em dash(\u2014)

 

if we cannot type the specific, a nice solution is to simply and replace all dashed with common regex --->\\p{Pd}

 

        /**

* for jira ticket C167868-3225:

* when user use an rare char EM dash instead of general '-'

* the system cannot recognise and would throw an exception, so shall resolue

* this situation

* @description

* @date Apr 12, 2017

* @author wc62923

*/

private static String validateAndReplaceInvalidateChar(String subjectline){

LOGGER.info("start validating the subject if it is available and not contains any rare character...");

subjectline = subjectline.replaceAll("\\p{Pd}", "_");

LOGGER.info("end validating the subject, mail received with subject line " + subjectline + " before deattaching the documents...");

return subjectline;

}

 

public static void main(String[] args){

System.out.println("asd-–—asd".replaceAll("\\p{Pd}", "_"));

System.out.print("43AA9822-–—EM—TEST".replaceAll("\u2014", "_"));

}

 

the log:

asd___asd

43AA9822-–_EM_TEST

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值