to intercept a string we can use the split method, split is divided by different separators to splitnow we want to intercept the regular matched content. Let's take a look at split. How to implement string segmentation>>> b= ' AAA,BBB,CCC '>>> b.split (', ')[' AAA ', ' BBB ', ' CCC '] so we're going to get the AAA section, how do we interceptmethod One:>>> b.split (', ') [0]' AAA ' Method Two:We can use the RE module to split the string with group, of course we use () to group the>>> Re.search (' ([a-z]*), ([a-z]*), ([a-z]*) ', b)<_sre. Sre_match object at 0x17e67e8>>>> Re.search (' ([a-z]*), ([a-z]*), ([a-z]*) ', b). Group (0)' AAA,BBB,CCC '>>> Re.search (' ([a-z]*), ([a-z]*), ([a-z]*) ', b). Group (1)' AAA '>>> Re.search (' ([a-z]*), ([a-z]*), ([a-z]*) ', b). Group (2)' BBB '>>> Re.search (' ([a-z]*), ([a-z]*), ([a-z]*) ', b). Group (3)' CCC '
Python's approach to string segmentation and interception