2011-09-25 369 views
2

我試圖寫一個正則表達式作爲替換操作的一部分使用。正則表達式匹配一個字符串,不以某個字符串結尾

我有如下許多路徑:

<ProjectReference Include="..\Common.Workflow\Common.Workflow.csproj"> 
<ProjectReference Include="..\Common.Workflow\Common.Workflow.Interfaces\Common.Workflow.Interfaces.csproj"> 
<ProjectReference Include="..\Common.Workflow\Common.Workflow.Persistence\Common.Workflow.Persistence.csproj"> 
<ProjectReference Include="..\Common.Workflow\Common.Workflow.Process\Common.Workflow.Process.csproj"> 

我需要替換在所有情況下Common.Workflow\除非了,它包含Common.Workflow.csproj

我將這些文件作爲代碼清理的一部分。

+0

你的意思是你想這樣做在Visual Studio ,還是編程? VS正則表達式與.NET正則表達式根本不同。 –

+0

並不多,我是世界上最倒黴的人:( – DaveShaw

+0

@TimPietzcker我沒有使用VS正則表達式。 – DaveShaw

回答

4

用您所需要的替換Common\.Workflow\\(?!Common\.Workflow\.csproj)

+0

謝謝,就是這麼做的。 – DaveShaw

2

使用負前瞻和負向後看,像這樣:

(?<!.*Common.Workflow.csproj)Common.Workflow\\(?!.*Common.Workflow.csproj) 

說明:

  • (?<!.*Common.Workflow.csproj)意味着「Common.Workflow.csproj不能出現比賽
  • (?!.*Common.Workflow.csproj)意思是「Common.Workflow.csproj一定不會出現匹配」

此正則表達式將防止匹配,如果Common.Workflow.csproj出現任何地方輸入(你沒有指定負僅匹配搜索後出現)

相關問題