
Base64 Regular Expression
Wednesday, February 14th, 2007
Here’s another thing I thought should have been easily accesible from a simple Google Search, but alas. This regular expression was created in C# .NET 2.0 to extract Base64 text from an InfoPath XML file so that my indexing algorithm wouldn’t waste its time on it. It will recognize Base64 strings 20 characters or greater (this is necessary, otherwise it will match good ‘ole english words as Base64). Simply change the 20 to a lower or higher number if you need to.
Oh yeah, here’s a cool link on working with Regular Expressions in .NET.
The Regular Expression
[0-9a-zA-Z\+/=]{20,}
The Code Snippet
string rawString = "";
FileInfo fInfo = new FileInfo("../../TextFile1.txt");
using (StreamReader sReader = new StreamReader(fInfo.Open(FileMode.Open)))
rawString = sReader.ReadToEnd();
Regex regExBase64 = new Regex(@"[0-9a-zA-Z\+/=]{20,}");
rawString = regExBase64.Replace( rawString, "" );
Here’s another thing I thought should have been easily accesible from a simple Google Search, but alas. This regular expression was created in C# .NET 2.0 to extract Base64 text from an InfoPath XML file so that my indexing algorithm wouldn’t waste its time on it. It will recognize Base64 strings 20 characters or greater (this is necessary, otherwise it will match good ‘ole english words as Base64). Simply change the 20 to a lower or higher number if you need to.
Oh yeah, here’s a cool link on working with Regular Expressions in .NET.
The Regular Expression
[0-9a-zA-Z\+/=]{20,}
The Code Snippet
string rawString = "";
FileInfo fInfo = new FileInfo("../../TextFile1.txt");
using (StreamReader sReader = new StreamReader(fInfo.Open(FileMode.Open)))
rawString = sReader.ReadToEnd();
Regex regExBase64 = new Regex(@"[0-9a-zA-Z\+/=]{20,}");
rawString = regExBase64.Replace( rawString, "" );
