@@ -261,28 +261,17 @@ private FindResults FindNameHelper(string packageName, string[] tags, bool inclu
261261
262262 // this regex pattern matches packageName followed by a version (4 digit or 3 with prerelease word)
263263 string regexPattern = $ "{ packageName } " + @"(\.\d+){1,3}(?:[a-zA-Z0-9-.]+|.\d)?\.nupkg" ;
264- Regex rx = new Regex ( regexPattern , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
265264 _cmdletPassedIn . WriteDebug ( $ "package file name pattern to be searched for is: { regexPattern } ") ;
266265
267266 foreach ( string path in Directory . GetFiles ( Repository . Uri . LocalPath ) )
268267 {
269268 string packageFullName = Path . GetFileName ( path ) ;
270- MatchCollection matches = rx . Matches ( packageFullName ) ;
271- if ( matches . Count == 0 )
272- {
273- continue ;
274- }
275-
276- Match match = matches [ 0 ] ;
277-
278- GroupCollection groups = match . Groups ;
279- if ( groups . Count == 0 )
269+ bool isMatch = Regex . IsMatch ( packageFullName , regexPattern , RegexOptions . IgnoreCase ) ;
270+ if ( ! isMatch )
280271 {
281272 continue ;
282273 }
283274
284- Capture group = groups [ 0 ] ;
285-
286275 NuGetVersion nugetVersion = GetInfoFromFileName ( packageFullName : packageFullName , packageName : packageName , actualName : out actualPkgName , out errRecord ) ;
287276 _cmdletPassedIn . WriteDebug ( $ "Version parsed as '{ nugetVersion } '") ;
288277
@@ -389,30 +378,19 @@ private FindResults FindVersionHelper(string packageName, string version, string
389378
390379 // this regex pattern matches packageName followed by the requested version
391380 string regexPattern = $ "{ packageName } .{ requiredVersion . ToNormalizedString ( ) } " + @".nupkg" ;
392- Regex rx = new Regex ( regexPattern , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
393381 _cmdletPassedIn . WriteDebug ( $ "pattern is: { regexPattern } ") ;
394382 string pkgPath = String . Empty ;
395383 string actualPkgName = String . Empty ;
396384
397385 foreach ( string path in Directory . GetFiles ( Repository . Uri . LocalPath ) )
398386 {
399387 string packageFullName = Path . GetFileName ( path ) ;
400- MatchCollection matches = rx . Matches ( packageFullName ) ;
401- if ( matches . Count == 0 )
402- {
403- continue ;
404- }
405-
406- Match match = matches [ 0 ] ;
407-
408- GroupCollection groups = match . Groups ;
409- if ( groups . Count == 0 )
388+ bool isMatch = Regex . IsMatch ( packageFullName , regexPattern , RegexOptions . IgnoreCase ) ;
389+ if ( ! isMatch )
410390 {
411391 continue ;
412392 }
413393
414- Capture group = groups [ 0 ] ;
415-
416394 NuGetVersion nugetVersion = GetInfoFromFileName ( packageFullName : packageFullName , packageName : packageName , actualName : out actualPkgName , out errRecord ) ;
417395 _cmdletPassedIn . WriteDebug ( $ "Version parsed as '{ nugetVersion } '") ;
418396
0 commit comments