https://gist.github.com/slotix/11f0930b2d46d2946249a10e6216735b#file-css3vsxpath-csv
2021年1月20日星期三
2021年1月17日星期日
Difference of BRE(Basic Regex) and ERE(Extended Regex) on using sed, grep, awk.
Special Chars:
BRE | . | [ | \ | * | ^ | $ | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
ERE | . | [ | \ | ( | ) | * | + | ? | { | | | ^ | $ |
ex. pattern for abc-adafaadsf abc adaadefaa
BRE: abc\|def ERE: abc|def
ex. pattern for match count.
BRE: abc\{3,5\} ERE: abc{3,5}
so, when using command of awk, grep, sed. don't forget using -r for ERE(extended regex).
but, when writing a shell script, using BRE is better, because 6 chars of 「.[\*^$」 are specials,
but there more special chars 「.[\()*+?{|^$」 for ERE.
Which is better, as you select.
2021年1月5日星期二
.net Regex Replace MatchEvaluator
public delegate string MatchEvaluator(Match match);
Examples
using System;
using System.Text.RegularExpressions;
class MyClass
{
static void Main(string[] args)
{
string sInput, pattern;
// The string to search.
sInput = "aabbccddeeffcccgghhcccciijjcccckkcc";
// A very simple regular expression.
pattern = "cc";
Regex r = new Regex(pattern);
// Assign the replace method to the MatchEvaluator delegate.
MatchEvaluator myEvaluator = new MatchEvaluator(ReplaceCC);
// Write out the original string.
Console.WriteLine(sInput);
// Replace matched characters using the delegate method.
sInput = r.Replace(sInput, myEvaluator);
// Write out the modified string.
Console.WriteLine(sInput);
}
// Replace each Regex cc match with the number of the occurrence.
public static string ReplaceCC(Match m)
{
i++;
return i.ToString() + i.ToString();
}
public static int i=0;
}
// The example displays the following output:
// aabbccddeeffcccgghhcccciijjcccckkcc
// aabb11ddeeff22cgghh3344iijj5566kk77
2021年1月4日星期一
linux sed replace with single/double quotation
$ echo \"aaaa\" | sed 's/"/1/g'
>1aaaa1
$ echo \'aaaa\' | sed 's/'\''/1/g'
>1aaaa1
订阅:
博文 (Atom)