.NET/C# Regular Expressions
Can't live without it! You know you can't! I know I can't!
C# Example Code
using System.Text.RegularExpressions;
Regex KGIDregex = new Regex(@"!KGID!([0-9]{10})!KGID!");
string TargetString = "!KGID!1111111111!KGID!dasdasdassadas";
Match KGIDmatch = KGIDregex.Match(TargetString);
if (KGIDmatch.Success) {
// KGIDmatch.Value = The whole matched string.
// KGIDmatch.Groups[1].Value = Contents within parentheses. (Index starts on 1, NOT zero).
} else {
// Boo!
}
Regex-based replacement
string what = "Nilsen's Eventyr på Snøen.mkv"; string pattern = "[^a-zA-Z0-9]"; string with = ""; // Replace (in this case remove) everything that's not alphanumeric. // Useful for e.g. generating filenames or identifier strings of sorts. Regex.replace(what,pattern,with);
Couple o' Extra Resources:
Regular Expression Language - Quick Reference (MSDN)
C# Regular Expressions Cheat Sheet - Mikesdotnetting
Regex Cheat Sheet - Regular Expression Library