7

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

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

例子

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

我真的很高兴有人可以帮我替换这个空格换行符来让文本看起来像这样

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

谢谢!

4

3 回答 3

16

尝试替换此正则表达式:

\s+,

有了这个:

,
于 2013-10-26T15:19:29.940 回答
6

您可以在这里做的另一个选择是使用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: 
于 2013-10-26T16:25:06.343 回答
0

另一个正面展望如下

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
于 2020-07-09T06:40:41.397 回答