2012-12-28 92 views
2

我正在使用記事本++和RegEx。在記事本的最後添加一個字符++

我有一個SRT文件,我想添加三個問號「???」每當一行的第一個三個字符也是三個問號「???」。但是,如果下一行是空白的,我只希望這樣做。但是,如果下一行不是空白,那麼我想添加???下一行結束後。

例如,這是我有。

14 
01:04:21,406 --> 01:04:24,887 
??? Face I'd never see again 

15 
01:04:24,885 --> 01:04:27,638 
??? It's a shame to awake 
in a world of pain 

現在我想添加???像這兩條線。

14 
01:04:21,406 --> 01:04:24,887 
??? Face I'd never see again ??? 

15 
01:04:24,885 --> 01:04:27,638 
??? It's a shame to awake 
in a world of pain ??? 

回答

1

記事本++用來解決多行匹配問題,但是當前的版本被認爲更好地支持Perl風格的正則表達式。我沒有安裝Notepad ++,但是如果它的正則表達式引擎工作正常,那麼以下正則表達式應該可以解決您的問題:

搜索(?s)^(\?{3}.*?(?=\r?\n\r?\n|\z))並替換爲\1???

說明:

(?s)   # Turn on dot-matches-all mode 
^   # Match start of line 
(   # Match and capture (group 1) 
\?{3}  # Three question marks 
.*?   # Any number of characters, as few as possible 
(?=   # until the following regex can be matched at the current position: 
    \r?\n\r?\n # Either two newlines in a row 
|   # or 
    \z   # the end of the file 
)   # End of lookahead assertion 
)   # End of capturing group 1 
+0

由於這是一個很大的幫助。做完之後,我發現有些情況下我不想添加???即使它從一開始。而是將它添加到下一行。 區別的因素是,如果一行開始???而下一行不是空白的,那我想補充一下???在下一行而不是以第一行開始? 這樣做的任何方式? – user1742965

+0

太棒了。非常感謝你 – user1742965

+0

@ user1742965:很高興聽到它。歡迎來到StackOverflow,我希望你能像我一樣發現它是一個很好的資源。 –

相關問題