1
目前我正在使用TextWrangler(mac)與grep查找/替換,但會同樣高興使用任何其他編輯器或命令行工具。找到多個子模式並用多個行代替使用textwrangler grep
我有這樣的結構(是的,有在每行的開頭有一個空格)的文本文件:
Reference 1 - This is a sentence with a period. And this exclaims! So does this one!
Reference 2 - This questions? And this, this one responds. But this YELLS!
,我需要保持基準,但打破每個句子到其自己的路線,像這樣:
Reference 1 - This is a sentence with a period.
Reference 1 - And this exclaims!
Reference 1 - So does this one!
Reference 2 - This questions?
Reference 2 - And this, this one responds.
Reference 2 - But this YELLS!
我可以讓它保持基準和最後一句與此(複製/替換換行符在那裏,這就是爲什麼在年底突破 - 否則它與其他文件相匹配T):
^([^-]+ -\s+)(?:([^.!?]+?[.!?]))(([^.!?]+?[.!?])+?)$
的更換是這樣的:
\1\2
\1\3
而結果是這樣的:
Reference 1 - This is a sentence.
Reference 1 - And this exclaims! So does this one!
Reference 2 - This questions?
Reference 2 - And this, this one responds. But this YELLS!
如果我跑了幾次,它不會永遠分離另兩個句子變成新的行。 但如果我添加其他行替換:
\1\4
然後我得到這個結果:
Reference 1 - This is a sentence.
Reference 1 - And this exclaims! So does this one!
Reference 1 - So does this one!
Reference 2 - This questions?
Reference 2 - And this, this one responds. But this YELLS!
Reference 2 - But this YELLS!
我的希望是,這是非常簡單的,我只是缺少一個開關/修改/等等。
如果我一次只能做一個句子,我不介意做其他清潔運行。
任何想法?
嘗試後,我得到了完全一樣的東西。 TextWrangler的GREP支持非貪婪匹配,所以你可以使用'(。+?[。!?])',但它似乎歸結爲相同的結果。 – usr2564301
完美的解決方案!謝謝!!!抱歉沒有早點回來。 –