1、 Greed and non greed
1. Greedy: as many matches as possible, (*) indicates greedy match
2. Non greedy: find the minimum content that meets the conditions Non greedy
3. Regular uses greedy matching by default
import re title = u"nameage" P1 = re. Compile (R ". *") (greedy mode) P2 = re. Compile (R ". *?") non greedy mode m1 = p1.search(title) print(m1.group()) m2 = p2.search(title) print(m2.group()) Two, XPATH 1. Definition: a set of rules / Languages for finding information in XML files, according to the elements of XML Document help: http://www.w3cshool.com.cn/xpath/index.asp 2. XPath development tools Open source XPath expression editing tool: xmlquire Chrome plug in: XPath Helper Firefox plug in: XPath Checker 3. How to select nodes in XML file (1) NodeName: Selects all children of this node (2) /: pick from root Example / student: no result /School: select the school node (3) //: select nodes regardless of location Example: // age: select three nodes, and the general composition list returns (4) .: select the current node (5) ..: select the parent node of the current node (6) @: select Properties (7) Searching in XPath is generally based on the path method School / Teacher: return to the teacher node School / student: return two student nodes //Student: select nodes of all students, regardless of location School // age: select all age nodes in the school descendants //@Other: select other attribute //Age [@ details]: select the age element with attribute details LiuDana 18 13260446055 ZhangSan 14 LiSi 19 15578875040 4. predicate /School / student : select the first student node under school /School / student [last()]: select the last student node under school /School / student [last() - 1]: select the penultimate student node under school /School / student [position() < 3]: select the first two nodes under school //Student [@ score]: select the student node with attribute score //Student [@ score = "99"]: select the student node with attribute score and attribute value 99 //Student [@ score] / age: select the child node age of the student node with attribute score 5. Some operations in XPath (1) | or For example: // student [@ score] | // Teacher: select the student node or teacher node with attribute score (2) Other unusual XPath symbols include +. -. *, div, >< Two, source code D31_2_GreedMatch.py D32_1_School.xml https://github.com/ruigege66/Python_learning/blob/master/D31_2_GreedMatch.py https://github.com/ruigege66/Python_learning/blob/master/D32_1_School.xml 2. CSDN: https://blog.csdn.net/weixin_ 3. Blog Park: https://www.cnblogs.com/ruige0000/ 4. welcome to pay attention to WeChat public number: Fourier transform, personal public number, only for learning exchanges, background reply "gift package", access to big data learning materials.