Welcome to the Mythicsoft Q&A site for:

- Agent Ransack
- FileLocator Lite
- FileLocator Pro

Please feel free to ask any questions on these products or even answer other community member questions.

Useful Links:

- Contact Us
- Help Manuals
- Mythicsoft Home
0 votes

I want to find all .csproj files that are not targeting a specific version of the .NET Framework. Here is the regular expression I'm starting with:

(<TargetFrameworkVersion>)(v4\.5\.1)(</TargetFrameworkVersion>)

This successfully identifies all files that are targeting .NET v4.5.1. For example, it will find the following string:

<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>

What changes would I need to make to my regular expression, if I want my search to match the following strings?

<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
by (40 points)

1 Answer

+1 vote
 
Best answer

To match the 3 specific versions in one expression try:

<TargetFrameworkVersion>v(2.0|4.5|4.5.2)</TargetFrameworkVersion>

However, in answer to the original question, ie "...not targeting a specific version...", if you wanted to list all the versions not targeting 4.5.1 you could use:

<TargetFrameworkVersion>(?!v4.5.1).*?</TargetFrameworkVersion>

If you just wanted to list the framework version for all files you could use this:

<TargetFrameworkVersion>v.*?</TargetFrameworkVersion>

Note: Strictly speaking I should've escaped the period in the version numbers since unescaped they'll actually match any character but this can make the regex hard to read and since the version numbers are only single digit it shouldn't be a problem.

by (29.5k points)
Perfect: (?!v4.5.1).*? is exactly what I was looking for.  Thank you so much!
...