Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Regex problem
Message
De
18/08/2006 08:31:17
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Divers
Thread ID:
01146684
Message ID:
01146689
Vues:
15
>Hello All, can anyone tell me why this RegEx is not working ?, basically I'm scanning directories looking for files with a .ogg extension, and renaming them with a .flac, ( yes it's my music collection :-) ) and thought this code would do the trick
>
>
>//Code snippet.
>// Assume dir is a DirectoryInfo object.
>
>FileInfo[] filesInDir = dir.GetFiles();
>
>Regex rx = new Regex(".ogg/i");
>
>foreach ( FileInfo file in filesInDir )
>{
>    MatchCollection theMatches = rx.Matches(file.FullName);
>
>    if (theMatches.Count > 0)
>        Console.WriteLine("Found a jpeg: {0}", theMatches[0].Value);
>}
>
>
>
>I know there are several hundred ogg files but this code doesn't find any, the other method would be to check file.Extension but I'm curious to know why this is failing


Looking for file.Extension would make more sense to me (and be faster).

I am not an expert on RegEx but IIRC the dot in front of ogg is looking for any character, not necessarily a dot. I do not know what the /i stands for. If you are looking for end of string that would be ogg$ or ogg\z.

If you wanted to look for the dot as a literal it would be \.ogg$


Alex Feldstein, MCP, Microsoft MVP
VFP Tips: English - Spanish
Website - Blog - Photo Gallery


"Once again, we come to the Holiday Season, a deeply religious time that each of us observes, in his own way, by going to the mall of his choice." -- Dave Barry
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform