Notepad++替换空格和逗号为逗号。

7
我完全不擅长Notepad++中的替换选项,但我用它来编辑我的txt文件以及一些txt格式的kindle电子书。
问题是,在某些行中,我遇到了这个问题:
例子
Emily是一个漂亮的女孩 ,但没有人真正喜欢她。
如果有人能帮我将空格-换行符替换为逗号,那就太好了,这样文本看起来就像这样:
Emily是一个漂亮的女孩,但没有人真正喜欢她。
谢谢!
3个回答

17

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

\s+,

有了这个:

,

6

在这里你还可以使用负向先行断言的另一种选择。

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

您可以在此处使用正向先行断言来向前查看,以查看是否存在非单词字符。
Find: \s+(?=\W)
Replace: 

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接