You can use there.split()function ofremodule allows you to split a string based on multiple delimiters specified by a regular expression pattern. This can be incredibly useful when you need more complex or flexible splitting logic than what is provided by thebuilt-insplit()method of strings. ...
We use the re.split() to split the string based on the occurrence of some pattern. To split a string using multiple delimiters, we specify multiple delimiters in the pattern. For example, 1 2 3 4 5 import re a = "split, the; string, multiple, delimiters" print(re.split('; |, ...
说明:字符串对象的split()只能处理简单的情况,而且不支持多个分隔符,对分隔符周围可能存在的空格也无能为力。 #example.py# #Example of splitting a string on multiple delimiters using a regeximportre#导入正则表达式模块line='asdf fjdk; afed, fjek,asdf, foo'#(a) Splitting on space, comma, and se...
https://python3-cookbook.readthedocs.io/zh_CN/latest/c02/p01_split_string_on_multiple_delimiters.html
# Example of splitting a string on multiple delimiters using a regex importre#导入正则表达式模块 line='asdf fjdk; afed, fjek,asdf, foo' # (a) Splitting on space, comma, and semicolon parts=re.split(r'[;,\s]\s*', line) print(parts) ...
解决方案1:【http://python3-cookbook.readthedocs.org/zh_CN/latest/c02/p01_split_string_on_multiple_delimiters.html】string对象的 split() 方法只适应于非常简单的字符串分割情形,它并不允许有多个分隔符或者是分隔符周围不确定的空格。当你需要更加灵活的切割字符串的时候,最好使用re.split() 方法:...
Related: In Python, you can split the string based on multiple delimiters.1. Quick Examples of Splitting a String by DelimiterIf you are in a hurry, below are some quick examples of how to split a string by a delimiter.# Quick examples of splitting a string by delimiter # Initialize the...
Splitting on Multiple Delimitersre.split can handle multiple delimiter types in one operation. multi_delimiter.py #!/usr/bin/python import re text = "apple,banana;cherry date:fig" result = re.split(r'[,;:\s]+', text) print("Split result:", result) This splits on commas, semicolons...
Regex to Split string with multiple delimiters In this section, we’ll learn how to use regex to split a string on multiple delimiters in Python. For example, using the regular expressionre.split()method, we can split the string either by the comma or by space. ...
说明:字符串对象的split()只能处理简单的情况,而且不支持多个分隔符,对分隔符周围可能存在的空格也无能为力。# example.py # # Example of splitting a string on multiple delimiters using a regex import re #导入正则表达式模块 line = 'asdf fjdk; afed, fjek,asdf, foo'# (a) Splitting on ...