JZTXT
  • 首页
  • Ai
  • Java
  • Python
  • Android
  • Mysql
  • JavaScript
  • Html
  • CSS

string replace multiple items

发布时间 2023-05-09 11:16:36作者: xiaoxuxli

Do a str.replace('; ', ', ') and then a str.split(', ')

or

import re
re.split('; |, ', string_to_split)

>>> a='Beautiful, is; better*than\nugly'
>>> import re
>>> re.split('; |, |\*|\n',a)
['Beautiful', 'is', 'better', 'than', 'ugly']

参考:
[1] https://stackoverflow.com/questions/4998629/split-string-with-multiple-delimiters-in-python

    本栏目推荐文章
  • js string转html节点
  • day4: BigDecimal类, Arrays类, 包装类, String类 , Collection+迭代器,增强for
  • String 类和 STL (Standard Template Library)
  • Java中BigDecimal类、String类和Number类
  • 解决TypeError: string indices must be integers, not str
  • Linq Orderby null,string.Empty, 指定字符
  • [LeetCode] 1363. Largest Multiple of Three 形成三的最大倍数
  • String字符串
  • CodeForces 1329D Dreamoon Likes Strings
  • [LeetCode] 2696. Minimum String Length After Removing Substrings
版权声明:本网站为非赢利性站点,本网站所有内容均来源于互联网相关站点自动搜索采集信息,相关链接已经注明来源。
联系我们