Skip to content

Instantly share code, notes, and snippets.

@piccaso
Created October 13, 2012 23:01
Show Gist options
  • Save piccaso/3886513 to your computer and use it in GitHub Desktop.
Save piccaso/3886513 to your computer and use it in GitHub Desktop.
regex 'reduce path' & y/n question
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
//using Sharpduino;
//using Sharpduino.Constants;
namespace ConsoleApplication1
{
class Program
{
static string regex_extract(string input, string pattern, RegexOptions regex_options = RegexOptions.None, int group = 1)
{
var match = Regex.Match(input, pattern, regex_options);
if (match.Success) return match.Groups[group].ToString();
return "";
}
static void Main(string[] args)
{
var key = @"C:\whatever\neno\neno\views\myneno\welcome.cshtml";
Console.WriteLine(regex_extract(key, @"\\[^\\]*\\[^\\]*\\[^\\]*\\[^\\]*$", group: 0));
Console.Write("Fix (y/n)");
var yn = Console.ReadKey().KeyChar.ToString().ToLower();
if (yn == "y" || yn == "j")
{
Console.WriteLine("yes");
}
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment