Created
June 2, 2014 15:41
-
-
Save hagbarddenstore/05835f266c56cc93de3c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static string Replace(string input, string regex) | |
{ | |
var match = System.Text.RegularExpressions.Regex.Match(regex, @"^s(.)(?<Regex>.*?)(?:(?<!\\)\1)(?<Replace>.*?)(?:(?<!\\)\1)$"); | |
var replaced = Regex.Replace(input, match.Groups["Regex"].Value, match.Groups["Replace"].Value); | |
return replaced; | |
} |
This file contains hidden or 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
var replaced1 = Replace("value", "s/value/VALUE/"); | |
Console.WriteLine(replaced1); // VALUE | |
var replaced2 = Replace("value/value", "s/value\\/value/VALUE/"); | |
Console.WriteLine(replaced2); // VALUE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment