简体   繁体   English

使用正则表达式查找并替换文本文件

[英]Find and replace in a text file using regular expressions

I have a few hundred .docx documents that I'm converting to markdown. 我有几百个要转换为降价的.docx文档。 I'm using textutil to convert the .docx to html and Pandoc to convert the html to Markdown. 我正在使用textutil将.docx转换为html,并使用Pandoc将html转换为Markdown。

The problem I have is that original .docx files contain dropcaps. 我的问题是原始.docx文件包含首字下沉。 In the text file I now have the first letter (which was the dropcap) separated from its paragraph by a line break. 现在,在文本文件中,我的第一个字母(即首字下沉)通过换行符与其段落分开。 it looks like this: 它看起来像这样:

T

he following five basic pre-conditions are essential...

I'm using a mac (10.6.8) and textmate. 我正在使用Mac(10.6.8)和Textmate。 Textmate allows a find and replace using regular expressions. Textmate允许使用正则表达式查找和替换。

How is it possible to remove the line break and rejoin the separated letter with the rest of its paragraph? 如何删除换行符,然后将分隔的字母重新插入其段落的其余部分?

For the search, try this: 对于搜索,请尝试以下操作:

^([A-Z])[\r\n]+(\w+)\b

For the replace: 对于替换:

$1$2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM