python - 在 Python 中的空格上拆分字符串

标签 python regex string split whitespace

我正在寻找与

等效的 Python
String str = "many   fancy word \nhello    \thi";
String whiteSpaceRegex = "\\s";
String[] words = str.split(whiteSpaceRegex);

["many", "fancy", "word", "hello", "hi"]

最佳答案

str.split()没有参数的方法在空格上拆分:

>>> "many   fancy word \nhello    \thi".split()
['many', 'fancy', 'word', 'hello', 'hi']

关于python - 在 Python 中的空格上拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8113782/

相关文章:

regex - 正则表达式匹配只能在字符串中出现一次的字符?

Python - 评估字符串中的数学表达式

c++ - 如何将已编译的正则表达式 (std::regex) 保存/序列化到文件中?

java - 为什么我不能使用 Scanner(System.in) 读取整行和 double?

Python:将字符串列表与元组列表进行比较,并根据匹配或不匹配创建新列表

python - Pandas :在 groupby 'date' 中删除重复项

Python打开文件过多(子进程)

python - Python 函数为什么以及如何是可散列的?

python - Flask 和 WTForms - 如何确定文件上传字段是否已提交用于处理目的

python - 如何更新 nltk 包以便它不会将电子邮件分成 3 个不同的标记?