This is the longest Regular Expression in Jq. I have been studying it for a long time and have been confused. I still feel that it is easier to understand the analysis value step by step through debugging.
The Code is as follows:
Var chunker = /((? :\((? : \ ([^ ()] + \) | [^ ()] +) + \) | \[(? : \ [[^ [\] * \] | ['"] [^'"] * ['"] | [^ [\]'"] +) + \] | \\. | [^> + ~, (\ [\] +) + | [> + ~]) (\ S *, \ s *)? ((? :. | \ R | \ n) *)/g,
This is the longest Regular Expression in Jq. I have been studying it for a long time and have been confused. I still feel that it is easier to understand the analysis value step by step through debugging,
I tried to make the image more intuitive and distinguished it by different colors, such:
Group 1 splits an array one by one using the following code:
The Code is as follows:
// Here, the loop is used to split each selector into a parts array. For example, p # id> p ul li is split into ['P # id', '>', 'P ', 'ul ', 'lil']
While ((chunker.exe c (""), m = chunker.exe c (soFar ))! = Null ){
// SoFar stores the separator string after the first layer, that is, group 3 on the image.
SoFar = m [3];
// The first part of the selector block is pushed into the array.
Parts. push (m [1]);
// If it is split into commas (,), the previous Group ends, jumps out of the loop, and goes to another group of selectors.
If (m [2]) {
// Record another set of selectors
Extra = m [3];
Break;
}
}
Others, such as ID and class, are easy to understand.
The Code is as follows:
Match :{
// \ U00c0-\ uFFFF matches letters of multiple countries or families
ID :/#((? : [\ W \ u00c0-\ uFFFF-] | \.) +)/, // For example: # myId
CLASS :/\.((? : [\ W \ u00c0-\ uFFFF-] | \.) +)/, // such as. myClass
NAME:/\ [name = ['"] * (? : [\ W \ u00c0-\ uFFFF-] | \.) +) ['"] * \]/, // For example: [name =" myName "]
ATTR:/\ [\ s *((? : [\ W \ u00c0-\ uFFFF-] | \.) +) \ s *(? :( \ S? =) \ S * (['"] *) (. *?) \ 3 |) \ s * \]/, // For example, [attribute = "value"]
TAG:/^ ((? : [\ W \ u00c0-\ uFFFF \ *-] | \.) +)/, // such as: p
CHILD:/:( only | nth | last | first)-child (? : \ (Even | odd | [\ dn +-] *) \)? //, // For example: first-child or: nth-child (5n + 1)
POS:/:( nth | eq | gt | lt | first | last | even | odd )(? : \ (\ D *)\))? (? = [^-] | $)/, // For example: nth (3) span
PSEUDO :/:((? : [\ W \ u00c0-\ uFFFF-] | \.) + )(? : \ (['"]?) ((? : \ ([^ \)] + \) | [^ \ (\)] *) +) \ 2 \))? ///: Jlkj \ kjl ('kl (kklk) kl ')
}
To be continued ......