【发布时间】:2016-10-26 15:47:04
【问题描述】:
我正在尝试使用我在此处找到的方法替换除 - 和 _ 之外的所有标点符号,但我只能使用发布的使用否定前瞻的确切代码来让它工作:
(?!")\\p{punct}
//Java example:
String string = ".\"'";
System.out.println(string.replaceAll("(?!\")\\p{Punct}", ""));
我试过了:
name = name.replaceAll("(?!_-)\\p{Punct}", ""); // which just replaces all punctuation.
name = name.replaceAll("(?!\_-)\\p{Punct}", ""); // which gives an error.
谢谢。
【问题讨论】:
-
如果你碰巧登录了,如果它对你有用,请考虑接受答案。
标签: java regex string character-class