|  |      1forty      2020-09-23 11:22:26 +08:00  2 定啥定啊,直接按连续 2 个换行符分割不就行了吗? | 
|  |      3umissthestars      2020-09-23 11:31:02 +08:00 /(\n.*?architecture\s?[::]\s?8.*?)(?!\n)/gi // example ``` const str = `processor : 0 BogoMIPS : 38.40 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 CPU implementer : 0x51 CPU architecture: 8 CPU variant : 0x2 CPU part : 0x201 CPU revision : 1 processor : 1 BogoMIPS : 38.40 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 CPU implementer : 0x51 CPU architecture: 8 CPU variant : 0x2 CPU part : 0x201 CPU revision : 1 processor : 2 BogoMIPS : 38.40 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 CPU implementer : 0x51 CPU architecture: 8 CPU variant : 0x2 CPU part : 0x205 CPU revision : 1 processor : 3 BogoMIPS : 38.40 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 CPU implementer : 0x51 CPU architecture: 8 CPU variant : 0x2 CPU part : 0x205 CPU revision : 1` ``` // output ``` ["↵processor : 1 BogoMIPS : 38.40 Features : fp asim… crc32 CPU implementer : 0x51 CPU architecture: 8", "↵processor : 2 BogoMIPS : 38.40 Features : fp asim… crc32 CPU implementer : 0x51 CPU architecture: 8", "↵processor : 3 BogoMIPS : 38.40 Features : fp asim… crc32 CPU implementer : 0x51 CPU architecture: 8"] ``` | 
|      4qazwsxkevin      2020-09-23 11:31:04 +08:00 import re tarString = "CPU architecture: 8" getStr = re.sub('(?<=:).*?(?=$")', 'utf-8', tarString) # 方法 2,必定是数字的话 getStr = re.findall(r"\d+",tarString) | 
|      5AzsharR OP @forty 因为每次,内容不同,所以需要定位 processor 这个关键词查看后面内容,但是又因为 processor 后面又很多空格定位不到 | 
|  |      6umissthestars      2020-09-23 11:33:53 +08:00 你这输入和我进来时的不一样了...你又偷偷更新了 | 
|      7AzsharR OP @umissthestars  别不好意思 因为呈现出来的格式打乱了 改了一下 | 
|      8caaaalabash      2020-09-23 16:39:31 +08:00 /(processor.+?)(?=processor)|(processor.+)(?=$)/sg | 
|      9wd941113      2020-09-29 10:50:40 +08:00 string = "processor:****" base_string_split = [{i.split(":")[0].strip(): i.split(":")[1].strip() for i in temp.strip("\n").split("\n")} for temp in string.split("\n\n")] for string_temp in base_string_split: processor = string_temp.get(processor) --over-- |