Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Photo.123.aspx
- Photo.10123.aspx
- Photo.12.aspx
- Photo.10012.aspx
- using System;
- using System.Text.RegularExpressions;
- namespace RenameAspxFile
- {
- sealed class Program
- {
- private static readonly Regex _aspxFileNameRegex = new Regex(@"(S+.)(d+)(.aspx)", RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);
- private static readonly string[] _aspxFileNames= {"Photo.123.aspx", "Photo.456.aspx", "BigPhoto.789.aspx"};
- static void Main(string[] args)
- {
- Program program = new Program();
- program.Run();
- }
- void Run()
- {
- foreach (string aspxFileName in _aspxFileNames)
- {
- Console.WriteLine("Renamed '{0}' to '{1}'", aspxFileName, AddTenThousandToPhotoNumber(aspxFileName));
- }
- }
- string AddTenThousandToPhotoNumber(string aspxFileName)
- {
- return _aspxFileNameRegex.Replace(aspxFileName, match => String.Format("{0}{1}{2}", match.Result("$1"), Int32.Parse(match.Result("$2")) + 10000, match.Result("$3")));
- }
- }
- }
- s(
- Photo. (d{2,3}) .aspx
- ){
- "Photo." . ($1 + 10000) . ".aspx"
- }xe
- "Photo./d.aspx" and replace with "Photo.1000$1.aspx"
- "Photo./d/d.aspx" and replace with "Photo.100$1.aspx"
- "Photo./d/d/d.aspx" and replace with "Photo.10$1.aspx"
- Regex regex = new Regex(@"(ddd?)", RegexOptions.None);
- string result = regex.Replace(@"Photo.123.asp", delegate(Match m)
- {
- return "Photo.1"
- + m.Groups[1].Captures[0].Value.PadLeft(4, '0')
- + ".aspx";
- }
- );
- static public string Evaluator(Match match)
- {
- return "Photo.1"
- + match.Groups[1].Captures[0].Value.PadLeft(4, '0')
- + ".aspx";
- }
- public void Code(params string[] args)
- {
- string pattern = @"Photo.([d]+).aspx";
- string test = "Photo.123.aspx";
- Regex regex = new Regex(pattern);
- string converted = regex.Replace(test, Evaluator)
- Console.WriteLine(converted);
- }
- [^d][d]{2,3}[^d]
- :s/Photo.d+.aspx/=Photo.submatch(0)+10000.aspx/g
Add Comment
Please, Sign In to add comment