【问题标题】:notepad++ replace space and , with ,notepad++ 将空格和 , 替换为 ,
【发布时间】:2013-10-26 15:17:39
【问题描述】:

我对notepad++中的替换选项完全不满意,但我用它来编辑我的txt文件和一些txt格式的kindle书籍。

问题是,在某些方面我遇到了这个问题:

例子

艾米丽是个漂亮的女孩 ,但没有人真正喜欢她。

如果有人可以帮我替换这个空格换行符来让文本看起来像这样,我会非常高兴

艾米丽是一个漂亮的女孩,但没有人真正喜欢她。

谢谢!

【问题讨论】:

    标签: regex notepad++


    【解决方案1】:

    尝试替换这个正则表达式:

    \s+,
    

    有了这个:

    ,
    

    【讨论】:

      【解决方案2】:

      您可以在此处执行的另一个选项是使用 Negative Lookahead

      Find: \s+(?![^,])
      Replace: 
      

      正则表达式:

      \s+            whitespace (\n, \r, \t, \f, and " ") (1 or more times)
       (?!           look ahead to see if there is not:
        [^,]         any character except: ','
       )             end of look-ahead
      

      或者先看一下是否没有单词字符。

      Find: \s+(?!\w)
      Replace:
      

      正则表达式:

      \s+            whitespace (\n, \r, \t, \f, and " ") (1 or more times)
       (?!           look ahead to see if there is not:
        \w           word characters (a-z, A-Z, 0-9, _)
       )             end of look-ahead
      

      您还可以在此处使用 Positive Lookahead 来查看是否有非单词字符。

      Find: \s+(?=\W)
      Replace: 
      

      【讨论】:

        【解决方案3】:

        另一个正向预测如下

        Find    : \s+(?=,)
        Replace :
        

        正则表达式:

        \s+            whitespace (\n, \r, \t, \f, and " ") (1 or more times)
         (?=           look ahead to see if there is :
           ,           comma
         )             end of look-ahead
        

        【讨论】:

          猜你喜欢
          • 2022-01-22
          • 2012-09-14
          • 2015-01-19
          • 2021-11-28
          • 2012-05-15
          • 1970-01-01
          • 1970-01-01
          • 2014-06-22
          • 2014-12-26
          相关资源
          最近更新 更多