2021年1月20日星期三

Difference between XPath and css selector


https://gist.github.com/slotix/11f0930b2d46d2946249a10e6216735b#file-css3vsxpath-csv


GoalCSS 3XPath
All Elements*//*
All P Elementsp//p
All Child Elementsp>*//p/*
Element By ID#foo//*[@id=’foo’]
Element By Class.foo//*[contains(@class,’foo’)]
Element With Attribute*[title]//*[@title]
First Child of All Pp>*:first-child//p/*[0]
All P with an A childNot possible//p[a]
Next Elementp + *//p/following-sibling::*[0]
Previous ElementNot possible//p/preceding-sibling::*[0]

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日星期一