自定义正则表达式

时间:2014-02-07 13:35:06

标签: regex notepad++

我试着用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' 

2 个答案:

答案 0 :(得分:1)

尝试使用:

找到:(.*:.*)\R\s*-
替换为:$1 -

答案 1 :(得分: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'