【发布时间】:2012-08-15 15:42:50
【问题描述】:
以下是我的长文摘录:
As a young researcher, he is required:
\n ÷ to read at least three theses\n ÷ to meet his tutor or supervisor
once a week\n ÷ to join seminars\n
现在我想找到以÷ 开头并以\n 结尾的任何块,并将÷ 替换为÷<font color="blue"> 和\n 替换为</font>\n。因此,例如,我上面的摘录将如下所示:
As a young researcher, he is required:
\n ÷<font color="blue"> to read at least three theses</font>\n ÷<font color="blue">
to meet his tutor or supervisor once a week</font>\n ÷<font color="blue"> to join seminars</font>\n
到目前为止,我一直在 TextWrangler 中使用这些 Grep 来查找和替换:
(÷[^ \t/<>]*?).*?([^ \t/<>]*?\\n)
<font color="blue">\1\2</font>\3
已成功找到所需的文本块,但替换没有按预期进行。
我正在使用 TextWrangler,但可能可以访问 BBEdit 或 Notepad++。
你能帮我解决这个问题吗?非常感谢。
更新
感谢 DesertEagle,我找到了解决方案。代码如下:
÷([^\\n]+)\\n
÷<font color="blue">\1</font>\\n
【问题讨论】:
-
替换是如何工作的?您可以发布该搜索和替换的结果吗?
标签: regex grep wildcard textwrangler