我正在寻找 Python 等价物
String str = "many fancy word \nhello \thi";
String whiteSpaceRegex = "\\s";
String[] words = str.split(whiteSpaceRegex);
["many", "fancy", "word", "hello", "hi"]
原文由 siamii 发布,翻译遵循 CC BY-SA 4.0 许可协议
我正在寻找 Python 等价物
String str = "many fancy word \nhello \thi";
String whiteSpaceRegex = "\\s";
String[] words = str.split(whiteSpaceRegex);
["many", "fancy", "word", "hello", "hi"]
原文由 siamii 发布,翻译遵循 CC BY-SA 4.0 许可协议
import re
s = "many fancy word \nhello \thi"
re.split('\s+', s)
原文由 Óscar López 发布,翻译遵循 CC BY-SA 3.0 许可协议
2 回答4.2k 阅读✓ 已解决
2 回答812 阅读✓ 已解决
1 回答4.1k 阅读✓ 已解决
2 回答2.1k 阅读✓ 已解决
3 回答794 阅读✓ 已解决
4 回答2.5k 阅读
1 回答2.7k 阅读✓ 已解决
没有参数的
str.split()
方法在空格上拆分: