我正在尝试使用在这里找到的方法替换所有标点符号,除了 - 和 _,但我只能在双引号上使用精确代码才能使其起作用,该代码使用了负向先行断言:
(?!")\\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.
感谢您。