2016-04-07 15 views
2

C# içinde, satırdaki tek deyim olan ve use $(trop) ifadesinin hemen önündeki tüm go ifadelerini bulacağınız normal bir ifade yazmaya çalışıyorum.Açgözlü olmayan negatif görünüm

Oldukça yakınım - go numaralı ifadelerin hepsini buluyor, ancak bunu doğru olarak elde edemiyorum - ilkinde ('Bunu yakalamak için' aşağıda işaretlenmiş şekilde bulundu), ama bilgi edemiyor Negatif gözünüzü düzgün bir şekilde çalışır hale getirin. Birisi bana yanlış yaptığım şeyle bana yardımcı olabilir mi?

set noexec off 
:setvar trop devtip 
:setvar trop_wf_tracking trop_workflow_tracking 
:setvar trop_wf trop_wf 

-- Information - to set this script to only run once change stop_if_applied to 1. 
:setvar stop_if_applied 1 


-- Do NOT catch this one 
use $(trop) 
go 



if $(stop_if_applied) = 1 and exists (select * from $(trop).dbo.DATABASE_VERSION where DB_SCRIPT_NUMBER = 20656) begin 
    select 'This db script has already been run. If it is required to run again change the variable stop_if_applied to 0. Disabling all further commands on the connection.' 
      ,* from $(trop).dbo.DATABASE_VERSION 
    where DB_SCRIPT_NUMBER = 20656 

    set noexec on 
    return 
end 

-- DO catch this one ---------- 
go 
-- ------------------------------------------------------------------------------ 

set xact_abort on 

begin transaction 

select * from $(trop).dbo.DATABASE_VERSION where DB_SCRIPT_NUMBER = 20656; 

/* Insert your code here */ 

select * from dbo.SECURITY_RIGHT 
-- DO catch this one ---------- 
go 

/* End of your code here */ 
-- DO catch this one ---------- 
go 

if not exists (select * from $(trop).dbo.DATABASE_VERSION where DB_SCRIPT_NUMBER = 20656) 
    insert into $(trop).dbo.DATABASE_VERSION (DB_SCRIPT_NUMBER, COMMENT) 
    values (20656, 'comment goes here'); 

select * from $(trop).dbo.DATABASE_VERSION where DB_SCRIPT_NUMBER = 20656; 

commit 
+1

Yok, bu SQL Server t-sql benziyor. Ayrıca, sorunuz normal ifadelerle ilgili ise, gönderiyi ihtiyacınız olan yardımı alma şansını artırmak için "regex" ile etiketlerdim. – gmiley

+0

Ayrıca, konudaki dili belirtmeye gerek yoktur. Bunu kontrol etmelisiniz: http://stackoverflow.com/help/how-to-ask –

+0

Çocuklar, bunun onun kodu olduğunu sanmıyorum. Sanırım bu ayrıştırmaya çalıştığı örnek. – Icemanind

cevap

1

Evet, görünüm, ^go'dan önce gitmelidir. `C#` ne burada sahip bir

(?m)        # Multi-line mode 
(?<! use \s* \$\(trop\) \s*)  # Not a 'use $(trop)` behind 
^         # Beginning of line 
\s* go       # The 'go' 
[^\S\r\n]*      # Optional horizontal whitespace 
(?= \r? \n | $)     # until the end of line or EOS 

C# testi

Regex RxGo = new Regex(@"(?m)(?<!use\s*\$\(trop\)\s*)^\s*go[^\S\r\n]*(?=\r?\n|$)"); 
Match matchGo = RxGo.Match(sTarget); 
while (matchGo.Success) 
{ 
    Console.WriteLine("'{0}'", matchGo.Value); 
    matchGo = matchGo.NextMatch(); 
} 
+0

Teşekkürler Bu hile yaptı. –

0

Bunu kullanmayı mümkün olmalıdır:

(?<!(use \$\(trop\)[\r\n]))^go$ 

Bu en azından, sizin örnekte çalışır

(?<goStatement>^(\s{0,})go(\s{0,})$)(?<useTrop>(?<!(^\s{0,}use \(trop\)\s{0,}$)))` 

İşte Arıyorum metin bu.

+0

Teşekkür ederim - ama bu işe yaramadı C# ... :( –

İlgili konular