2014-02-07 109 views
-2

我試圖用Notepad ++編寫正則表達式,以便如果一行以' - '開頭,表達式會將該行追加到緊接其前一行的那一行,該行還包含冒號':'。 見下面的例子:自定義正則表達式

3) In the query dialog select: 
    - Query Source: 'blah' 
    - Client: 'blah' 
    - From Date: 30/09/2012 00:00:00 
    - To Date: 01/01/2014 00:00:00 
4) Enter the query terms as follows: 
    - 'URL' 
    - 'Contains' 
    - 'google' 

Turns into: 
3) In the query dialog select: Query Source: 'blah' - Client: 'blah' - From Date: 0/09/2012 00:00:00 - To Date: 01/01/2014 00:00:00 
4) Enter the query terms as follows: - 'URL' - 'Contains' - 'google' 
+0

'我trying' - 看起來並不像它迄今。 – devnull

+0

正則表達式不要操縱字符串......並且你到目前爲止嘗試過嗎? –

回答

1

有一試:

查找內容:(.*:.*)\R\s*-
替換:$1 -

+0

這將連接一對相鄰的線。替換將需要多次加入所有行。示例輸入四次。但我不認爲有什麼辦法可以避免重複,所以這是一個很好的答案。 – AdrianHHH

+0

@AdrianHHH:只需點擊「全部替換」按鈕。 – Toto

+0

剛試過再次更換。做一個**替換所有**不會將' - '包含''和' - 'google''行加入到'4)...'URL'行。 – AdrianHHH

0

該工程─

正則表達式 - (?:\r\n)\s*([-].*?)

更換與 - \1

一個單獨的全部替換它。

示例 -

Original text- 
3) In the query dialog select: 
    - Query Source: 'blah' 
    - Client: 'blah' 
    - From Date: 30/09/2012 00:00:00 
    - To Date: 01/01/2014 00:00:00 
4) Enter the query terms as follows: 
    - 'URL' 
    - 'Contains' 
    - 'google' 

After Replace All- 

3) In the query dialog select:- Query Source: 'blah' - Client: 'blah'- From Date: 30/09/2012 00:00:00- To Date: 01/01/2014 00:00:00 
4) Enter the query terms as follows:- 'URL'- 'Contains'- 'google' 
+1

問題要求「包含冒號」,而不僅僅是以冒號結尾的行。我認爲這個答案不會加入' - 查詢源:'blah''和' - 客戶端:'blah''。 – AdrianHHH

+0

即使不包含冒號,也會連接所有行。 – Toto

+0

是的,但是OP給出的例子'URL' - 'Contains' - 'google'也被添加了。所以剛剛搜索了' - '。 – Kamehameha