2012-07-12 25 views
0

我想使用此工具來美化SQL代碼。在此工具接受之前,我希望使用替換功能將「< *>」(不包括雙引號)的每個實例替換爲TextPad中的「\ n \ n \ n \ n \ n」(5個新行),並選擇正則表達式。我怎樣才能做到這一點?Textpad正則表達式:用5個新行替換一組3個字符

enter image description here

http://www.dpriver.com/pp/sqlformat.htm

insert into i2b2demodata.QUERY_GLOBAL_TEMP (patient_num , panel_count) select patient_num ,1 as panel_count from (select /*+ index(observation_fact fact_cnpt_pat_enct_idx) */ patient_num from i2b2demodata.observation_fact where concept_cd IN (select concept_cd from i2b2demodata.concept_dimension where concept_path LIKE '\i2b2\Reports\%') AND (valtype_cd = 'B' AND contains(observation_blob,'Arthritis') > 0) group by patient_num) t <*> insert into i2b2demodata.DX (patient_num) select * from (select distinct patient_num from i2b2demodata.QUERY_GLOBAL_TEMP where panel_count = 1) q <*> insert into i2b2demodata.MASTER_QUERY_GLOBAL_TEMP(master_id, patient_num, level_no) select 'masterid:22', patient_num, 0 from i2b2demodata.QUERY_GLOBAL_TEMP where patient_num IN (select patient_num from i2b2demodata.QUERY_GLOBAL_TEMP where panel_count = 1) <*> delete i2b2demodata.DX <*> delete i2b2demodata.QUERY_GLOBAL_TEMP <*> insert into i2b2demodata.QUERY_GLOBAL_TEMP (patient_num , panel_count) select patient_num ,1 as panel_count from (select /*+ index(observation_fact fact_cnpt_pat_enct_idx) */ patient_num from i2b2demodata.observation_fact where concept_cd IN (select concept_cd from i2b2demodata.concept_dimension where concept_path LIKE '\i2b2\Diagnoses\Digestive system (520-579)\%') group by patient_num) t <*> update i2b2demodata.QUERY_GLOBAL_TEMP set panel_count = 2 where i2b2demodata.QUERY_GLOBAL_TEMP.panel_count = 1 <*> update i2b2demodata.QUERY_GLOBAL_TEMP set panel_count = -1 where i2b2demodata.QUERY_GLOBAL_TEMP.panel_count = 2 and exists (select 1 as panel_count from (select /*+ index(observation_fact fact_cnpt_pat_enct_idx) */ patient_num from i2b2demodata.observation_fact where concept_cd IN (select concept_cd from i2b2demodata.concept_dimension where concept_path LIKE '\i2b2\Diagnoses\Circulatory system (390-459)\%') group by patient_num having count(distinct patient_num || '|' || encounter_num || '|' || provider_id || '|' || instance_num || '|' ||concept_cd || '|' ||cast(start_date as varchar(50))) >= 3) t where i2b2demodata.QUERY_GLOBAL_TEMP.patient_num = t.patient_num group by patient_num) <*> insert into i2b2demodata.DX (patient_num) select * from (select distinct patient_num from i2b2demodata.QUERY_GLOBAL_TEMP where panel_count = 2) q <*> delete i2b2demodata.MASTER_QUERY_GLOBAL_TEMP where master_id = 'masterid:22' and level_no >= 1 <*> <*> insert into i2b2demodata.MASTER_QUERY_GLOBAL_TEMP(master_id, patient_num, level_no) select 'masterid:21', patient_num, 0 from i2b2demodata.QUERY_GLOBAL_TEMP where patient_num IN (select patient_num from i2b2demodata.QUERY_GLOBAL_TEMP where panel_count = 2) <*> delete i2b2demodata.DX <*> delete i2b2demodata.QUERY_GLOBAL_TEMP <*> insert into i2b2demodata.QUERY_GLOBAL_TEMP (patient_num , panel_count) select patient_num ,1 as panel_count from (select patient_num from i2b2demodata.MASTER_QUERY_GLOBAL_TEMP where master_id = 'masterid:22' group by patient_num) t <*> update i2b2demodata.QUERY_GLOBAL_TEMP set panel_count =2 where exists (select 1 as panel_count from (select patient_num from i2b2demodata.MASTER_QUERY_GLOBAL_TEMP where master_id = 'masterid:21' group by patient_num) t where i2b2demodata.QUERY_GLOBAL_TEMP.panel_count = 1 and i2b2demodata.QUERY_GLOBAL_TEMP.patient_num = t.patient_num) <*> insert into i2b2demodata.DX (patient_num) select * from (select distinct patient_num from i2b2demodata.QUERY_GLOBAL_TEMP where panel_count = 2) q 
+0

您正在尋找正則表達式<*>,它會查找所有右括號(>)或開括號,緊接着是右括號(<>)。這是因爲*意味着在它之前找到0個或更多的角色。最後,這是否必須用TextPad完成?我很肯定在Notepad ++中做這件事很簡單。 爲了幫助我理解你想要什麼,你可以在之前顯示文本,文本之後? – 2012-07-12 01:27:23

+0

請參閱單詞「實例」。將第一個帶引號的字符串的每個實例替換爲新的帶引號的字符串。 – MacGyver 2012-07-12 02:17:46

回答

1

正則表達式匹配< *>是<\*>

+0

但結果是字符串「\ n \ n \ n \ n \ n」,而不是5個新行。 – MacGyver 2012-07-12 02:19:54

+0

我認爲這是你的文本編輯器的限制。這不是正則表達式的問題。您可以嘗試從文本編輯中複製「新文件」並將其粘貼到替換字段上。它將顯示爲空白字段。 – 2012-07-12 03:50:56

+0

我猜你的答案中的第一句話是正確的,而第二句是不正確的。請將其更改爲將「<*>」替換爲「<\\*>」,並將其標記爲正確。 – MacGyver 2012-07-12 11:08:15