使用正则表达式在每行的开头和结尾添加空格

时间:2017-11-15 12:12:26

标签: regex adobe-brackets

正如标题所示,我需要在文本文档中每行的开头和结尾添加空格字符。

以下是文字的摘录:

56
00:04:28.620 --> 00:04:32.070
and a little sturdier sounding, but it
also alters the articulation of it.

57
00:04:32.070 --> 00:04:35.310
So that's what's kind of cool about
parallel compression, you kind of beat

58
00:04:35.310 --> 00:04:39.790
something up a little bit and blend it in,
and you get the best of both worlds.

我正在使用Brackets(OSX)并且希望有人可以帮我找到一个可以在find& amp;中使用的正则表达式。替换功能,但当然,欢迎任何更好的建议!

原因: 我正在准备这个大型的成绩单(+100000行)进行文本分析,需要在进入MATLAB的分析仪之前进行准备。

1 个答案:

答案 0 :(得分:0)

通过外观,您可以搜索这些位置:

^(?=\S)|(?<=\S)$

这些职位需要由\替换,请参阅a demo on regex101.com

<小时/> 细分:

^(?=\S)  # ^ = start of line (multiline mode) 
         # plus making sure there's no whitespace immediately ahead
|        # or
(?<=\S)$ # pos. lookbehind and end of string/line