2

I an trying to write a regular expression to be used as part of a replace operation.

I have many paths as follows:

<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">

I need to replace the Common.Workflow\ in all cases except where the it contains Common.Workflow.csproj.

I am moving these files as part of a code clean up.

3
  • Do you mean you want to do this in Visual Studio, or programmatically? VS regexes are fundamentally different from .NET regexes. Commented Sep 25, 2011 at 21:29
  • Not much, I'm the worlds most hapless regex person :( Commented Sep 25, 2011 at 21:30
  • @TimPietzcker I'm not using VS Regex. Commented Sep 25, 2011 at 21:30

2 Answers 2

4

Replace Common\.Workflow\\(?!Common\.Workflow\.csproj) with what you need.

Sign up to request clarification or add additional context in comments.

Comments

2

Use a negative look-ahead and a negative look-behind, like this:

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

Explanation:

  • (?<!.*Common.Workflow.csproj) means "Common.Workflow.csproj must not appear before the match
  • (?!.*Common.Workflow.csproj) means "Common.Workflow.csproj must not appear after the match"

This regex will prevent matching if Common.Workflow.csproj appears anywhere in the input (you didn't specify that the negative match only appears after the search)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.