` ` `
1, XXXXX2, XXXXX, XXXX 3, XXXXX
` ` `
How can I get
` ` `
1, XXXXX
2, XXXXX, XXXX
3, XXXXX
` ` `
Such an array? (no language)
I use python regular segmentation,
` ` `
STR="1, aaaaa2, BBBBB, bb, 3 ccccc4, DDDD"
Res=re. Split (' \ d (. *?) \ 'd, STR)
` ` `
The result is
` ` `
[' aaaaa ', 'CCCCC]
How to write to get
[" aaaaa ", "BBBBB ', 'CCCCC', 'DDDD'] (also line with serial number)
` ` `
CodePudding user response:
The split should be regular "\ d +," lineBut I don't know will appear abnormal data, such as: 1, aaa2, bbb3, a1234, xxx5, adsa
This data can only use the code in order to distinguish the, solve the problem or from the root, return a json array directly, do not return this extremely easy to cause ambiguity format
CodePudding user response:
Already find a solution to writeThe import re
S="1, aaaaa2, BBBBB, bb, 3 ccccc4, DDDD"
Res=re. The.findall (' \ d \ d + 's)
Print (res)