Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在大写字母[Regex]前插入逗号的一种Python方法_Python_Regex - Fatal编程技术网

在大写字母[Regex]前插入逗号的一种Python方法

在大写字母[Regex]前插入逗号的一种Python方法,python,regex,Python,Regex,我的Regex fu严重不足,我无法控制它。。。得到的任何帮助都是巨大的 我正在寻找一种Python方法来解析一个非常旧的软件(我没有源代码访问权限)所吐出的字符串: ,Areas for further improvement,The school’s leaders are rightly seeking to improve the following areas:,,========2========,,3/5,Continue to focus on increasing perfor

我的Regex fu严重不足,我无法控制它。。。得到的任何帮助都是巨大的

我正在寻找一种Python方法来解析一个非常旧的软件(我没有源代码访问权限)所吐出的字符串:

,Areas for further improvement,The school’s leaders are rightly seeking to improve the following areas:,,========2========,,3/5,Continue to focus on increasing performance at the higher levelsPupils’,literacy and numeracy skills across the curriculumStandards,in science throughout the schoolPupils’,numerical reasoning skills
我想做的是:

(1) 删除所有现有的
,:=/
字符以形成单个连续字符串:

Areas for further improvementThe school’s leaders are rightly seeking to improve the following areas23/5Continue to focus on increasing performance at the higher levelsPupils’literacy and numeracy skills across the curriculumStandardsin science throughout the schoolPupils’numerical reasoning skills
然后在每个大写字母前面加上一个
,以允许我使用字符串作为合理的csv输入

,Areas for further improvement,The school’s leaders are rightly seeking to improve the following areas23/5,Continue to focus on increasing performance at the higher levels,Pupils’literacy and numeracy skills across the curriculum,Standardsin science throughout the school,Pupils’numerical reasoning skills
我很感激这会给我一个先例,但我可以在我写文件时去掉它

这可以通过
re.sub()
和正则表达式fu实现吗

(很高兴这是一个分为两步的过程-删除现有的垃圾字符,然后添加,在大写字母之前)

有人能帮我保存一下正则表达式吗

干杯

输出:

',Areas for further improvement,The school’s leaders are rightly seeking to improve the following areas235,Continue to focus on increasing performance at the higher levels,Pupils’literacy and numeracy skills across the curriculum,Standardsin science throughout the school,Pupils’numerical reasoning skills'
输出:

',Areas for further improvement,The school’s leaders are rightly seeking to improve the following areas235,Continue to focus on increasing performance at the higher levels,Pupils’literacy and numeracy skills across the curriculum,Standardsin science throughout the school,Pupils’numerical reasoning skills'

您可以应用
re.sub
两次:

import re
s = ',Areas for further improvement,The school’s leaders are rightly seeking to improve the following areas:,,========2========,,3/5,Continue to focus on increasing performance at the higher levelsPupils’,literacy and numeracy skills across the curriculumStandards,in science throughout the schoolPupils’,numerical reasoning skills'
new_s = re.sub('[A-Z]', lambda x:f',{x.group()}', re.sub('[,:\=]+', '', s))
输出:

',Areas for further improvement,The school’s leaders are rightly seeking to improve the following areas23/5,Continue to focus on increasing performance at the higher levels,Pupils’literacy and numeracy skills across the curriculum,Standardsin science throughout the school,Pupils’numerical reasoning skills'

您可以应用
re.sub
两次:

import re
s = ',Areas for further improvement,The school’s leaders are rightly seeking to improve the following areas:,,========2========,,3/5,Continue to focus on increasing performance at the higher levelsPupils’,literacy and numeracy skills across the curriculumStandards,in science throughout the schoolPupils’,numerical reasoning skills'
new_s = re.sub('[A-Z]', lambda x:f',{x.group()}', re.sub('[,:\=]+', '', s))
输出:

',Areas for further improvement,The school’s leaders are rightly seeking to improve the following areas23/5,Continue to focus on increasing performance at the higher levels,Pupils’literacy and numeracy skills across the curriculum,Standardsin science throughout the school,Pupils’numerical reasoning skills'

社区期待着看到一些尝试。社区期待着看到一些尝试。工作了一顿,我理解了嵌套的re.sub——人们只是知道正则表达式的东西,还是在互联网上的某个地方有秘密的调味品来构建表达式?你可以练习。嵌套零件不太硬。这就像
b=re.sub(e1,r1,a);c=re.sub(b,e2,r2,b)
。哎呀,那应该是
re.sub(e2,r2,b)
做了一顿款待,我理解了嵌套的re.sub——人们只知道正则表达式的东西吗,或者在互联网上的某个地方有秘密酱来构建表达式?你可以练习。嵌套零件不太硬。这就像
b=re.sub(e1,r1,a);c=re.sub(b,e2,r2,b)
。哎呀,那应该是
re.sub(e2,r2,b)