2012-08-15 61 views
0

下面是我的長文的摘錄替換它們:如何找到的文本,並使用正則表達式

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 ++。

你能幫我解決這個問題嗎?非常感謝你。


UPDATE

感謝DesertEagle,我已經制定了解決方案。下面是代碼:

÷([^\\n]+)\\n 
÷<font color="blue">\1</font>\\n 
+0

如何更換操作?你可以發佈搜索結果並替換嗎? – 2012-08-15 15:50:11

回答

1

雖然我沒有在手的TextWrangler,這應該爲你[1]

搜索工作 /÷([^\n]+)\n/

編輯 正確的語法對於textwrangler是 ÷([^\\n]+)\\n

更換 ÷<font color="blue">\1</font>\n

[1]請確保正確轉義爲您的引擎

+0

非常感謝,但沒有找到。 – 2012-08-15 15:59:44

+0

嘗試用'*'替換'+' – DesertEagle 2012-08-15 16:03:56

+0

不,窗臺不起作用(我在TextWrangler中)。 – 2012-08-15 16:05:46