添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
public static String delRepeatSym1 ( String str ) { if ( StringUtils . isEmpty ( str ) ) { return "" ; // 可以根据要求添加 标点符号 Pattern compile = compile ( "[,。!\\”\\?]" ) ; StringBuffer content = new StringBuffer ( ) ; // 下标变更 AtomicInteger index = new AtomicInteger ( 0 ) ; char [ ] contentChars = str . toCharArray ( ) ; for ( int i = 0 ; i < contentChars . length ; i ++ ) { String curStr = String . valueOf ( contentChars [ i ] ) ; Matcher matcher = compile . matcher ( curStr ) ; boolean del = matcher . find ( ) ; content . append ( curStr ) ; // 是符号 不是第一个 if ( del && i > 0 ) { // 上一个 String strPre = String . valueOf ( contentChars [ i - 1 ] ) ; Matcher matcherPre = compile . matcher ( strPre ) ; // 重复了 if ( matcherPre . find ( ) ) { content . deleteCharAt ( i - index . getAndIncrement ( ) ) ; return content . toString ( ) ; public static void main ( String [ ] args ) { String content = "欢迎阅读【字符串操作-正则】-文本字符串中多余重复出现的标点符号截取最后一个的文章,,多多点赞。。谢谢!!。" ; String result = delRepeatSym1 ( content ) ; System . out . println ( result ) ;
  1. 用到真正表达式配置标点符号
  2. 通过 StringBuffer 在遍历中重新拼接,没有通过记录重复的下标,再次遍历del重复的数据
  3. 注意重新拼接, deleteCharAt 后的越界问题
1、逗号分隔 英文 字符串 ,不能在首尾 出现 间有且仅有 一个 逗号 const reg = /^(?!,)(?!.*,$)[\u4e00-\u9fa5a-zA-Z]+(?:[,][\u4e00-\u9fa5a-zA-Z]+)*$/g; const reg = /^(?!,)(?!.*,$)[\u4e00-\u9fa5a-zA-Z]+(?:[,][\u4e00-\u9fa5a-zA-Z]+)*$/g; if (reg.test(value)) { callback(); public static void main(String[] args) { String str = "group-banner-top-http://pic/test/20220225092606e0dc59c3ef8c915b8fbe9f99153b7ef9"; //获取第 一个 "-"后面的所有 字符串 int index = str.indexOf("-"); System.out
def remove_punctuation(text): # 匹配 英文 标点符号 punctuation_pattern = re.compile('[^\u4e00-\u9fa5^a-z^A-Z^0-9]') # 将匹配到的 标点符号 替换为空格 text = punctuation_pattern.sub(' ', text) # 去除 多余 的空格 text = re.sub('\s+', ' ', text).strip() return text text = '这是一段只含有 英文 标点符号 字符串 ,需要去除。' text = remove_punctuation(text) print(text) 输出结果为:这是一段只含有 英文 标点符号 字符串 需要去除 IDEA配置xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)解决方法,亲测有效 41730 IDEA配置xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)解决方法,亲测有效 newzhong1: 忽略是idea工具监测按快捷提示后选择忽略,这个是无法访问对应的对应,通过这个这种方式手动添加 IDEA配置xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)解决方法,亲测有效 这不就是,,,,忽略错误了。。。 IDEA配置xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)解决方法,亲测有效 敲代码的ikun: IDEA配置xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)解决方法,亲测有效 dark_corrupt: