Created
October 13, 2012 23:01
-
-
Save piccaso/3886513 to your computer and use it in GitHub Desktop.
regex 'reduce path' & y/n question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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