我想删除一个句子中的单词,如果这个单词开始或包含某些字符
例:
string_s = '( active parts ) acetylene cas89343-06-6'
若单词包含cas或以cas开头,则从字符串中删除整个单词
input1 = '( active parts ) acetylene cas89343-06-6'
output1 = '( active parts ) acetylene'
input2 = '( active parts ) acetylene th.cas1345'
output2 = '( active parts ) acetylene'
一艘班轮:
将
re.sub
与模式\b[\w-]*cas[\w-]*\b
一起使用,并替换为单个空格,然后修剪输出:这张照片是:
您可以通过以下方式完成此操作:-
相关问题 更多 >
编程相关推荐