简体   繁体   English

Java正则表达式-匹配拆分词

[英]Java regex - match splitted words

I have a problem with matching words at the end of line, that contains dash ( - ). 我在行尾匹配单词时遇到问题,该单词包含破折号( - )。

For example: 例如:

circum-
stances

My regex matches this as 2 words (circum, stances) , But I need to remove dash and the sign of new line a make one word. 我的regex匹配为2个单词(circum, stances) ,但是我需要删除破折号和换行符来制作一个单词。

Try this, 尝试这个,

public static void main(String[] args) {
        String str = "circum-\nstances";
        System.out.println("[Original Content:"+str+"]");
        str = str.replaceAll("-(\\s+)", "");
        System.out.println("[Modified Content:"+str+"]");
    }

You'll get this as the output, I believe this is what you were looking for. 您将获得此输出,我相信这就是您想要的。

run:
[Original Content:circum-
stances]
[Modified Content:circumstances]
BUILD SUCCESSFUL (total time: 0 seconds)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM